I have a Blazor component who is composed of one div included in an @if directive (IsVisible). The div has an @ref. When the component is rendered, IsVisible is false. My component has a method (Show()) who set IsVisible to true and use the reference to the div. But the reference is always null (no Context and no Id).
@if (IsVisible)
{
<div @ref="MyRef">Bla bla bla</div>
}
@code {
bool IsVisible = false;
ElementReference MyRef;
public void Show()
{
IsVisible = true;
StateHasChanged();
// here, MyRef has no Context and no Id
}
}