C
C#16mo ago
leleco

❔ Blazor - Get objects from child components

I have a page called "FactorSearch", that calls 2 instances of the same component, called "scope". Scope has 4 properties: Region, Universe, StartDate, EndDate. What I'm trying to do is, when I click "GetScope", I get an instance of the object Scope filled with the informations within each of the instances I created. Been trying to search about it but no success. Thanks!
No description
2 Replies
friedice
friedice16mo ago
In your page, create 2 reference variables correlating to that component you would want to initialize and add a @ ref to them So something like
cs
<ComponentA @ref="@_ref1" />
<ComponentA @ref="@_ref2"/>

@code{
private ComponentA _ref1;
private ComponentA _ref2;

//Do something with references here
}
cs
<ComponentA @ref="@_ref1" />
<ComponentA @ref="@_ref2"/>

@code{
private ComponentA _ref1;
private ComponentA _ref2;

//Do something with references here
}
Note that this can cause performance issues depending on how tightly coupled you want your component to be to your parent
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?