Reputation: 1
I need to communicate between 3 components in blazor in the code behind.
Note : The Child-1 component acts as intermediate it doesn't have any UI elements
This is the concept, I don't how to call the child-1 component in the code behind of parent
Example : [In Parent Component]
<button @onclick="callChildOne">Submit<button/>
void callChildOne(){
// i need to call child-1 here and pass the parameter status
// i need help in writing this code
}
REFER THIS IMAGE FOR BETTER UNDERSATNDING
Upvotes: 0
Views: 1026
Reputation: 1
I founded the case and came up with answer in terms of blazor. Refer below example
Child2.razor
@code{//some code}
Child1.razor
//No UI, only methods in code behind
@code{
public void Show()
{
// TODO actual implementation for calling child 2 component
}
}
Parent.razor
<button @onclick="callChildOne">Submit<button/>
@*Add a @ref to the component *@
<Child1 @ref="childObj"></Child1 >
@code {
//Hold the reference to the component
private Child1 childObj;
// Call the public methods of the component
private void callChildOne() => childObj.Show();
}
This is how I mapped relationship with 3 components without any service. I read this example from blog of Blazor here
Upvotes: 0