Life Cycle Event Of Blazor

Before we get to the main topic let’s have a  quick introduction to Blazor.
 
Blazor is the latest framework to create interactive client side UI using web assemblies. Now, many users wonder why they should use Blazor, since there are lots of front end technologies available in the market.
 
 
So here is the answer. With Blazor: 
  • You can create a interactive UI with C# without Javascript
  • Both client side and server side logic will be written in .Net so if user doesnt have a knowledge of Javascript they can also create application
  • It renders components so it also gives good support in mobile browsers
  • Follows .Net architecture and will give you .Net securities
There are so many things to cover in Blazor. It has a component based structure so it will create a single page application

Move on to the Lifecycle
  1. SetParameterAsync - it will call before initializing component to set parameters on app-start.
    1. Public override async Task SetParameterAsync(Parameterview parameter)  
    2. {  
    3.    await base.SetParameterAsync(parameter)  
    4. }  
OnInitialize
 
It will call when initializing any component
  1. Public overridevoid OnInitialized()  
  2. {  
  3. }   
Also there’s an async method for this
  1. Public override async Task OnInitializedAsync()  
  2. {  
  3.    await...  
  4. }   
OnParameterSet
 
It works as an after parameter set.
  1. Public overridevoid OnParameterSet()  
  2. {  
  3. }   
Also there’s a async method for this
  1. Public override async Task OnParameterSetAsync()  
  2. {  
  3.    await...  
  4. }   
OnAfterRender
 
It will call after rendering the component:
  1. Public overridevoid OnAfterRender(bool firstrender)  
  2. {  
  3. }   
Also there’s an async method for this:
  1. Public override async Task OnAfterRenderAsync(bool firstrender)  
  2. {  
  3.    await...  
  4. }    
This method is mostly used to call any javascript function to avoid runtime error. 
 
Thanks for reading this article. Please find the attached sample project; it will help you to understand the flow.
Next Recommended Reading Starting With Blazor + MudBlazor