I have a user control that needs to load a child control when a button is clicked. The problem is that it needs to request a control from another class.
So, in the button click event, I call the function to get my control, and add it to the page, for example:
UserControl ctrl = ExampleDataProvider.GetControl(some params...);
myDetailPane.Controls.Add(ctrl);
The GetControl method looks like this:
public static UserControl GetControl(some params...)
{
ExampleDetailPane ctrl = new ExampleDetailPane();
ctrl.Value = "12";
ctrl.Comment = string.Empty;
return ctrl;
}
This does not work because of the page life cycle — the child_Load page of the control is launched and its controls are set to zero.
I seem to know that my approach is wrong and why, but I don’t know how best to fix it! Can anyone help?