Search code examples
asp.net-corerazorblazor

Does blazor do a postback when using things like @onclick?


If not how does it get the information from server without postback?


Solution

  • No, it doesn't.

    These are the three most essential features of Blazor:

    1. It allows you to do almost everything in C#, i.e. with much less JavaScript.
    2. It sends and receives partial page updates via a constant series of SignalR communications, rather than huge post / reload events.
    3. Since it's .NET, it gives you access to all the libraries that come with the .NET framework, instead of having to rely on javascript or JQuery libraries.

    Here's an example of HOW responsive it is. In the handler for a FileInput, I can do something like:

       async Task HandleFileUpload(InputFileChangeEventArgs e)
        {
            int counter = 0;
            foreach (var imageFile in e.GetMultipleFiles(maxAllowedFiles))
            {
                ProgressMessage = $"Processing image: {++counter} / {e.FileCount} ";
                StateHasChanged(); // The user sees the update progress info RIGHT NOW
                // 
                // Do the file transfer, convert and resize it with .NET System.Drawing library
                //
            }
         }
    

    The user is getting the updated progress message before each file is transferred, processed and saved.