如何找到从网页到用户控件的面板 [英] how to find panel from webpage to usercontrol
本文介绍了如何找到从网页到用户控件的面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我有一个用户控件,aspx页面中有一个网页(aspx),我有两个面板.
我想从aspx页面到usercontrolpage找到2个面板.
请寄给我任何人.
谢谢
hi all
I have one usercontrol, one webpage (aspx) in aspx page i have two panels.
i want to find 2panels from aspx page to usercontrolpage.
PLease send me anyone.
Thanks
推荐答案
System.Web.UI.WebControls.Panel myPanel = null;
Control ctl = this.Parent;
while (true)
{
myPanel = (System.Web.UI.WebControls.Panel)ctl.FindControl("myPanel");
if (myPanel == null)
{
if (ctl.Parent == null)
{
return;
}
ctl = ctl.Parent;
continue;
}
break;
}
为面板创建属性,然后公开这些属性.之后,您将可以从UC访问.
例如.
Create property for panel and then expose those. After that you will be able to access from UC.
for ex.
public string MyPanel
{
get { return panelName; }
}
或者您可以使用以下技术.
Or you can use below technique.
protected void UCMethod()
{
Page myParent = this.ParentPageName;
Panel panel = myParent.PanelId; //Here you can access any property of parent page
}
这篇关于如何找到从网页到用户控件的面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文