-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsquestion
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
I would like component B to be able to access component A declaratively.
Ex 1: Consider this markup (using the ref attribute):
ComponentA @ref="compA"
ComponentB ComponentA="compA" // where "ComponentA" is a Parameter on Component B
code {
ComponentA compA;
}
Rule:
As I understand, this will not work because accessing components from life cycle methods except "OnAfterRender" is not possible.
-
Q:
How do I achieve something similar what's shown in the example in Blazor? Accessing controls by ID in webforms is a common pattern. -
Q:
Why is the rule (that I stated) not followed consistently about component references.
Ex 2: Consider this markup:
<input @ref="inputField" />
code
{
protected override void OnInitialized()
{
base.OnInitialized();
var refToInputField = inputField; // The reference exists, but this will not work for components; Why is there this inconsistency? Is this because I am referencing an HTML element instead of Blazor component?
}
}
- Current documentation is either off or not explicit about this:
Goto:
https://learn.microsoft.com/en-us/dotnet/architecture/blazor-for-web-forms-developers/components
Look under heading: Capture component references
This example is incomplete (in terms of context) and misleading. The OnSomething() is method from where?
Describe the solution you'd like
Questions are stated in the problem.
Additional context
No response
Metadata
Metadata
Assignees
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsquestion