Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

361
Views
How to open and close a blazor page using Onclick

I have a button where I open a blazor page currently I use the css display changing between none and block.

But I want to change the way this works, what I thought I'd add to open the page when I click on the button and close when I click on the other one

The opened razor page must open inside the main window.

I use the button as follows:

<svg class="Mybutton" viewBox="0 0 50 50" @onclick="() => OpenConf()">
    ...
</svg>


void OpenMenu() {
    SRuntime.InvokeAsync<string>("OpenConf");
}


function OpenConf() {
    document.getElementById("navi").style.display = "block";
}

Is there any way to open and close the page created in a razor file?

To be clearer, an example.

I have the main window and in that window I have a Config button.

When I click on this button it opens the razor file with the code for this page and when I click on the button inside this page it closes

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Good start.

One thing to keep in mind when writing with Blazor is that you very rarely need JS, which can help you reach a solution.

Firstly - remember that Blazor detects state and will update the page accordingly. Hence, we can create a bool to remember if the page should be shown/hidden.

@code
{
   private bool _pageShown = true;
}

Now lets create a button to toggle this Boolean

<button @onclick="() => _pageShown = !_pageShown">Toggle</button>

Note that this is a lambda function, because this is an EventHandler.

Finally, lets add an if statement

@if (_pageShown)
{
   <p>
      Content we might want to show, but we also might want to hide this...
   </p>
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!