FindControl returns null for UserControl
See original GitHub issueHi,
I’ve updated to the latest CI build that uses XAMLIL.
Now the FindControl if used inside the ctor returns null for UserControl example:
public ImageColorReplacePage()
{
this.InitializeComponent();
this.Initialized += (s, e) =>
{
// FindControl after the Initialization is complete works
var thisWontBeNull = this.FindControl<KitItemInformationView>("kitView");
};
// FindControl within the Constructor won't find anything
var thisOneWillBeNull = this.FindControl<KitItemInformationView>("kitView");
}
Repro project: https://github.com/braca/avalonia-findcontrol-bug
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
this.Parent.FindControl returns NULL when called from a ...
On one of it's click events, I call (Label)this.Parent.FindControl("lblRequestNumber"); and it works ok, returning the label that I want.
Read more >Page.FindControl() Returning Null Issues and Solutions ...
A developer without understanding the situation could assume FindControl() will return a control found within that page. This is completely ...
Read more >Nested controls in UserControl return null (FindControl) - Wrox
I have a UserControl that has some controls inside. I want to refer those controls after, in another postback. But when I try...
Read more >FindControl null - is there a way to identify control ID's?
FindControl ("TextBoxA") it will return null because it doesn't "own" any controls named TextBoxA. If you want to traverse the control hierarchy, ...
Read more >On page _load find control recursive function return null
i use this function for find control on page its working fine on button click but not working on page load its return...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone who wants a workaround, here’s a method you can use:
You would put TemporaryFix<T>() in your class since this.LogicalChildren is actually protected for UserControls. You could put it in some utils class if you pass this.LogicalChildren as another parameter instead.
Unfortunately, it isn’t #8231