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
-
SetParameterAsync - it will call before initializing component to set parameters on app-start.
- Public override async Task SetParameterAsync(Parameterview parameter)
- {
- await base.SetParameterAsync(parameter)
- }
OnInitialize
It will call when initializing any component
- Public overridevoid OnInitialized()
- {
- }
Also there’s an async method for this
- Public override async Task OnInitializedAsync()
- {
- await...
- }
OnParameterSet
It works as an after parameter set.
- Public overridevoid OnParameterSet()
- {
- }
Also there’s a async method for this
- Public override async Task OnParameterSetAsync()
- {
- await...
- }
OnAfterRender
It will call after rendering the component:
- Public overridevoid OnAfterRender(bool firstrender)
- {
- }
Also there’s an async method for this:
- Public override async Task OnAfterRenderAsync(bool firstrender)
- {
- await...
- }
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.