Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to perform state change of a Blazor component through its instance. Error - The render handle is not yet assigned

$
0
0

I am trying to alter a flag of a component through its instance but getting an error as The render handle is not yet assigned.

I have a component called PopMessage.razor

@if (isDisplay){<div><span>Message</span></div>}@code{    private bool isDisplay = false;    public void PopShow()    {        try        {            isDisplay = true;            StateHasChanged();        }        catch (Exception ex){}    }}

Registered it as builder.Services.AddScoped<PopMessage>()

And in an another component Home.razor

@page "/"@inject PopMessage _popMessage<button @onclick="PopPrint">Pop message</button><PopMessage/>@code{    private void PopPrint()    {        _popMessage.PopShow();    }}

Now on click of the button it throws the exception message as The render handle is not yet assigned in the PopShow method.

I did not really understand the issue. The component <PopMessage/> is loaded. But on he call of the message PopShow throws this exception. Without StateHasChanged() it does not throw the exception but of course the state does not get updated.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>