Live Chat Icon For mobile
Live Chat Icon

How do I suppress the UI rendering in Blazor?

Platform: Blazor| Category: Components

Override the ShouldRender method  to suppress UI rendering. If the implementation returns true, the UI is refreshed. Initial rendering cannot be prevented using this method.

[Counter.razor] 

@page "/counter" 

<PageTitle>Counter</PageTitle> 
<h1>Counter</h1> 
<p role="status">Current count: @currentCount</p> 
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button> 

@code { 
    private int currentCount = 0; 
    private bool shouldRender = true; 
    private void IncrementCount() 
    { 
        shouldRender = false; 
        currentCount++; 
    } 
    protected override bool ShouldRender () 
    { 
        return shouldRender; 
    } 
} 

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.