如何从用户控件访问页面控件? [英] How to access page controls from user control?
本文介绍了如何从用户控件访问页面控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有从用户控件访问页面控件的方法。我在我的网页一些控件,我想从用户控件访问这些控件。
解决方案
YourControlType ltMetaTags = NULL;
控制CTL = this.Parent;
而(真)
{
ltMetaTags =(ControlType)ctl.FindControl(控件名称);
如果(ltMetaTags == NULL)
{
CTL = ctl.Parent;
如果(ctl.Parent == NULL)
{
返回;
}
继续;
}
打破;
}
示例
System.Web.UI.WebControls.Literal ltMetaTags = NULL;
控制CTL = this.Parent;
而(真)
{
ltMetaTags =(System.Web.UI.WebControls.Literal)ctl.FindControl(ltMetaTags);
如果(ltMetaTags == NULL)
{
如果(ctl.Parent == NULL)
{
返回;
}
CTL = ctl.Parent;
继续;
}
打破;
}
Is there a way to access page controls from user control . I have some controls in my page and i want to access these controls from the user control .
解决方案
YourControlType ltMetaTags = null;
Control ctl = this.Parent;
while (true)
{
ltMetaTags = (ControlType)ctl.FindControl("ControlName");
if (ltMetaTags == null)
{
ctl = ctl.Parent;
if(ctl.Parent == null)
{
return;
}
continue;
}
break;
}
Example
System.Web.UI.WebControls.Literal ltMetaTags = null;
Control ctl = this.Parent;
while (true)
{
ltMetaTags = (System.Web.UI.WebControls.Literal)ctl.FindControl("ltMetaTags");
if (ltMetaTags == null)
{
if(ctl.Parent == null)
{
return;
}
ctl = ctl.Parent;
continue;
}
break;
}
这篇关于如何从用户控件访问页面控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文