Closed Indrajith-Sync closed 4 years ago
@Indrajith-Sync thanks for contacting us.
We're not sure we understand your scenario. Could you provide a minimal repro with detailed steps to illustrate your scenario, what you are expecting to happen and what is happening?
Hi @javiercn
Actually i am rendering a server side component in blazor. i Have initiated the code section part of the rendering and after that i need to call the StateHasChanged to make changes in the above defined Component tags.Here, I am facing issue in this in-between cycle as (The render handle is not yet assigned) from the StateHasChanged() which is in the code block section as mentioned in the example above.
@Indrajith-Sync Your snippet doesn’t have enough context for us to understand your issue. Could you provide a minimal repro project as we asked?
We can’t see where in which context you are calling something that calls statehaschanged.
Otherwise we won’t be able to help you.
/ Code behind source / (Razor file)
<MyComponent Content="@dialog.Content" Header="@dialog.Header" />
@code { public void Alert(string args) { dialog = new Dialog() { Content = args, Header = "Information" }; this.StateHasChanged(); // Getting an exception here during the run-time as mentioned above. } }
/ My razor code / (From this file i am calling my source file defined above)
<Component @ref="compRef"></Component>
@code {
compRef.Alert("Testing");
}
Can you understand the issue now. I don't have any repo project since my project is only under implementation.
Hi @javiercn
Here is the sample repo (https://github.com/Indrajith-Sync/Blazor). In this repo in Index.razor
file i have initialized MyComponent
and trying to create it during the runtime on a button click.
We understand now. Thanks for the clarification. The framework is responsible for the lifetime of the components.
If you instantiate a component yourself, it is not attached to the Blazor rendering process in any way.
I’m not exactly sure what you are trying to accomplish, but I suggest you look into using a component reference instead. See https://docs.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.1#capture-references-to-components for details
Currently in my project i am creating a component(Server-side), While calling the
StateHasChanged()
.It throws an exception error
The render handle is not yet assigned
.<div>@Updatedvalue</div>
@code {
public string Updatedvalue;
public void function() {
Updatedvalue = "Render part is called".
StatehasChanged() // Getting exception in this line and the render part is not called.
}
Is there any other way to called the render part of the code section after the code block is executed.Since i am rendering the component dynamically on a button Click is there any possibility to achieve this scenario ?