Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazored LocalStorage SetItemAsStringAsync not working in a button-triggered page function

$
0
0

I have a Blazor (.net 8) page code function that uses Blazored.LocalStorage.ILocalStorageService to set a page cookie. If I execute the SetItemAsStringAsync in a page event, say OnAfterRenderAsync, it works. However, what I want is a "login" button that once triggered sets the cookie - so it calls a function that performs SetItemAsStringAsync - and when I set a breakpoint on that line and step over it, the next line is never executed, and the page is refreshed.

In other words, I want to set the user email address in a local storage cookie when he clicks the "Login" button, not on page load. If I use the set item function in page load, it works - but in a button, it does not.

Here is my code:

private async Task UserLogin(){   var loginresult = Utils.AuthenticateUser(authUser.Email, authUser.Password);   var user = await Utils.DataInterface.GetUser(authUser.Email);   if (loginresult)   {      await localStorage.SetItemAsStringAsync("website.login", user.Email);   }}

The above fails. The user variable is an object returned from an EntityFramework database call.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>