I have created an usercontrol
that has treeview
inside.
Now I have placed it in an aspx page
twice with some different Id
let us say usercontrolA
and usercontrolB
.
Both of them are loaded in to page one by one.
Now in pre-render event
of usercontrolA
I want to get the object of treeview
control of usercontrolB
.
How can I achieve it?
You need to have the instance of usercontrolB
to access the treeview
control for both the user controls. So try preserving the instance in some appropriate storage to access it in the pre-render
event.
Introduce a property to hold the UC Type inside the User-Control
:
public MyUserControl MainUserControl { get; set; }
In the parent ASPX set the property with usercontrolB
:
usercontrolA.MainUserControl = usercontrolB;
usercontrolB.MainUserControl = usercontrolB;
Now you can use the MainUserControl
property to access your TreeView
:
MainUserControl.treeView1 ...
This example for finding a "usercontrolB" named treeview on any control on this form.
Control[] ctrl = this.Controls.Find("usercontrolB", true);
if (ctrl != null && ctrl.Length > 0)
{
TreeView tv = (TreeView)ctrl[0];
// do whatever you want with the treeview
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With