Introduction
Right from the moment the razor component comes alive there are a series of methods that get called based on different states of the component. We should have a clear understanding of the flow of the control. Today I will teach you different life cycle methods of razor components and when to call what.There are specifically 8 methods that come under this component life cycle.
Let's start from the beginning by knowing the architecture of the blazor page and moving forward we'll learn various synchronous and asynchronous methods.
The following image shows different parts of the razor page.

Image 1. Sample blazor component
In some scenarios, we want C# code to run first, and then UI to render. So the objects we are binding in the UI will have data. For e.g. List will get filled up with 4 items first then UI knows there are 4 rows in DataGrid. On the flip side, sometimes we want UI to render first and then C# code to run.
How to achieve all this? That's what we are going to learn today. Let's begin with the first state.
1. OnInitialized andOnInitializedAsync
These 2 methods are called before the component is rendered, First, we make service calls to fill all the objects which are then bound on the screen.
Let's see this in action.
Create a Parent and a Child component and add the instance of the Child component inside Parent. Refer to the image below.

Image 2. Create Parent and Child Component
Parents look something like this.
@page "/parent"
<Child></Child>
@code
{
}
Listing 1. Parent.razor
Child component: We are going to haveList<string> to keep the track of number of events being added.
<h4>Following are the life cycle events called as per the order of execution.</h4>
<br />
@foreach (string item in Events)
{
<h6>@item</h6>
<br />
}
@code
{
List<string> Events = new();
protected override void OnInitialized()
{
Events.Add("1. OnInitialized");
}
protected override async Task OnInitializedAsync()
{
Events.Add("2. OnInitializedAsync");
await Task.Delay(2000);
}
}
Listing 2. Child.razor
If you run this app, you'll notice this. When the app starts, these 2 methods are called first. In the same order as follows.

Image 3. Output of listing 1 and 2
2.OnParametersSet andOnParametersSetAsync
These methods are invoked by 2 triggers.
- Every time new parameters are received from the parent these methods are called.
- When the component is loaded for the first time these methods are called right after OnInitialized() and OnInitializedAsync().
To see this in action, we need to make a bit of changes in our components.
The parent component will now send a parameter named "counter" to the child component and also be responsible for updating the value of this counter. We can achieve this with a button click.
@page "/parent"
<h4> Parent: </h4>
<button onclick="@IncreaseCounter"> Update Counter</button>
<hr>
<Child Counter="@Counter"></Child>
@code
{
public int Counter { get; set; }
private void IncreaseCounter()
{
Counter++;
}
}
Listing 3. Parent.razor
Now for the child component, it will receive the parameter from the parent and show the value of that parameter in UI. This is where we will expose our 2 methods OnParametersSet() and OnParametersSetAsync().
<h5> Child: </h5>
<h6>Counter : @Counter</h6>
<h5>Life cycle events as per the order of execution.</h5>
<br />
@foreach (string item in Events)
{
<h6>@item</h6>
<br />
}
@code
{
[Parameter]
public int Counter { get; set; }
List<string> Events = new();
protected override void OnInitialized()
{
Events.Add("1. OnInitialized");
}
protected override async Task OnInitializedAsync()
{
Events.Add("2. OnInitializedAsync");
await Task.Delay(2000);
}
protected override void OnParametersSet()
{
Events.Add("3. OnParametersSet");
}
protected override async Task OnParametersSetAsync()
{
Events.Add("4. OnParametersSetAsync");
await Task.Delay(2000);
}
}
Listing 4. Child.razor
Now observe the series of images below and notice the flow.
Scenario1. The application runs for the first time, and the order of execution is as follows OnInitialized() => OnInitializedAsync()=> OnParametersSet() =>OnParametersSetAsync().

Image 4. Component Initialized
Scenario 2. The button on the parent component is clicked once, which sends the updated "counter-parameter" to the child component, you can see how OnParametersSet() and OnParametersSetAsync() get called again.

Image 5. The new parameter is sent from the parent to the child component.
Scenario 3. The Button clicked once again and the same pattern is observed in the child component.

Image 6. The new parameter is sent from the parent to child component.
3. OnAfterRender and OnAfterRenderAsync
These methods are called after the component is rendered. More on this later.
If you look at the syntax shown in the following snippet, you'll see these methods have one boolean parameter firstRender, the value of firstRender is true if the component is rendered for the first time else it is false.
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
Console.WriteLine("OnAfterRender: first render");
}
else
{
Console.WriteLine("OnAfterRender: after first render");
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
Console.WriteLine("OnAfterRenderAsync: first render");
}
else
{
Console.WriteLine("OnAfterRenderAsync: after first render");
}
await Task.Delay(1000);
}
Listing 5. OnAfterRender andOnAfterRenderAsync










Benabdessamad AymenPosted Nov 10, 2025, 1:07 PM
In the Listening 5,In the lifecycle order, how can OnAfterRender be executed before OnParametersSet?, if u r talking bout parent component, would u mention that please cuz it's confusing
V Madhusudhan VmsPosted Jul 11, 2024, 4:54 PM
Nice Explanations with specific necessary points, why not Microsoft is not following the same instead simply spoling by adding useless diversions. Really Appreciate... Keep sharing... Great
IMAD AYOUBPosted Apr 15, 2023, 7:05 PM
Very useful article. Thanks a lot.