none
Async update string RRS feed

  • Question

  • 	StrSaveText = "Saving...";
    	try
            {
                bool BlResult = await SaveData.SaveDeclaration(aProperty);
                if (BlResult == true)
                {
                    StrSaveText = "Saved";
                }
                else { 
                    StrSaveText = "Couldn't save!";
                }
            }
            catch (Exception e)
            {
                StrSaveText = "Couldn't save!";
            }

    I need some help as to why the above code works as it does.

    I use the string "StrSaveText" in blazor, to update the text of a save-button. Guessing this is all down to C#: the variable StrSaveText never updates after I set it on the first line. If I step through code with breakpoints it hits the lines that should update the variable, but this is never reflected on the button text, that should show the new text. Why is this?

    • Moved by CoolDadTx Friday, November 22, 2019 2:58 PM ASP.NET related
    Friday, November 22, 2019 12:43 PM

All replies

  • Have you verified from Visual studio Locals windows that it does not update the variable value (or other option is to assert it in code with Debug.Assert)? Your code does not include where it is set as button text, so error might be in somewhere else.
    Friday, November 22, 2019 1:28 PM
  • It does update the code when I step through it.The button text is initially set when I declare the string variable, so no errors there. Perhaps it's a Blazor thing then? It's seems like the variable is set, I can see that when I step though the code.

    I'm unsure about everything since c#, Blazor and async is rather new to me.

    Friday, November 22, 2019 1:35 PM
  • Since this question is related to Blazor which is an ASP.NET technology please post in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, November 22, 2019 2:57 PM