查找在同一页面另一个用户控制用户控制的控制 [英] Find user-control's control from another user-control in same page
问题描述
我已经创建了一个用户控件
有树状
里面。
现在,我已经在 aspx页面与一些不同的
和编号
让我们说 usercontrolA把它放在
两次 usercontrolB
。
两者都在一个页面由一个加载。
现在 pre-渲染
我想获得 usercontrolA
事件的对象
控制。 usercontrolB
的树状
我怎样才能实现呢?
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?
推荐答案
您需要具备的实例的的usercontrolB
访问同时为用户控件树视图
控制。因此,尝试的 preserving 的一些合适的存储实例访问它在 pre-渲染
事件。
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.
-
介绍一个属性来保存UC键入
用户控制在
:
public MyUserControl MainUserControl { get; set; }
在父ASPX设置财产 usercontrolB
:
usercontrolA.MainUserControl = usercontrolB;
usercontrolB.MainUserControl = usercontrolB;
现在,你可以使用 MainUserControl
属性来访问你的 TreeView控件
:
MainUserControl.treeView1 ...
这篇关于查找在同一页面另一个用户控制用户控制的控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!