Click here to Skip to main content
15,747,169 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to Blazor and Razor. When my Blazor webpage starts up, I want to execute code in the "Load event" that will click the first list item (id="li_for_APage") so that the @Body will contain APage. But I can not find the "Load event". The code below is in my MainLayout.Razor. Can someone please tell me what I need to do. Thanks

<div id="divButtons">
    <ul class="nav nav-pills nav-fill">
        <li id="li_for_APage" class="nav-item">
            <NavLink class="nav-link" href="APage">
                <span></span> APage
        <li id="li_for_BPage" class="nav-item">
            <NavLink class="nav-link" href="BPage">
                <span></span> BPage
        <li id="li_for_CPage" class="nav-item">
            <NavLink class="nav-link" href="CPage">
                <span></span> CPage

What I have tried:

I've tried calling code from index.cshtml and I've looked into the Program.cs
Updated 17-Oct-22 6:10am

I found the videos at Blazor Train[^] to be very useful when trying to understand Blazor. Nice bite sized chunks of focused information.

Also you might check out Chris Sainty - Building with Blazor[^]. He is literally writing the book.
Share this answer
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search using your subject as the search term gave 12,000 hits: Where is the "load event" in blazor? - Google Search[^]
The top hit gives code: In Blazor how to call a function at Page Load (event name)? - Stack Overflow[^]

In future, please try to do at least basic research yourself, and not waste your time or ours.
Share this answer
[no name] 31-Jul-21 11:39am    
I had already found the link that you provided. But the article did not say where to put the OnInitializedAsync override. YOU DID NOT ANSWER ANYTHING. But you did show everyone what an A$$H@|E you are!!!
OriginalGriff 31-Jul-21 11:54am    
Please be careful with your language - we do not tolerate abuse here.
[no name] 31-Jul-21 12:13pm    
I already turned you and your abusive reply into CodeProject
Dave Kreskowiak 31-Jul-21 18:09pm    
LOL. Yeah, you have no idea who 'Griff is.
Pete O'Hanlon 6-Aug-21 6:49am    
I guess I was the last report. He's outta here now.
Ironic that I googled the same thing, and came here to a link to a dude telling me to google it.
Share this answer
CHill60 17-Oct-22 12:18pm    
Ironic that you have posted a solution that is not a solution
Graeme_Grant 17-Oct-22 18:26pm    
5'ed if I only could! :P

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900