Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to override OnAfterRenderAsync in client side blazor

In my Blazor client-side app, I am trying to override OnAfterRenderAsync using

@code {
    protected override async Task OnAfterRenderAsync()
    {

    }
}

I get an error

no suitable methods to override!?

On the other hand this override works just fine:

protected override async Task OnInitializedAsync()
{

}

Any clues what is wrong here?

like image 350
mko Avatar asked Nov 07 '19 17:11

mko


2 Answers

Quoting ASP.NET Core and Blazor updates in .NET Core 3.0 Preview 9's Upgrade an existing project:

  • Replace OnAfterRender() and OnAfterRenderAsync() implementations with OnAfterRender(bool firstRender) or OnAfterRenderAsync(bool firstRender).

Since NET Core 3.0 Preview 9 OnAfterRender receives a boolean parameter to let method know if this is the first render. Very useful to avoid controlling it by yourself:

Git hub code upgrading to preview 9

Sample about how to replace old code to new one, red old code, green new one.

like image 78
dani herrera Avatar answered Nov 12 '22 09:11

dani herrera


try this

@code {
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {

    }
}

Note that both OnAfterRenderAsync and OnAfterRender has a boolen parameter you may call firstRender

 protected override async Task OnInitializedAsync()
    {

    }

Indeed, that should work with no issues as this is the correct method signature of OnInitializedAsync

like image 44
enet Avatar answered Nov 12 '22 10:11

enet