本文介绍了要o访问母版页中的内容页控件怎么可能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人
要o访问母版页中的内容页控件怎么可能
请还原
Dear All
Want o Access Content page Control in Master Page how come posible
please revert
推荐答案
MasterPage s = new MasterPage();
Page p = (Page)s.FindControl("pagename");
Label la=(Label) p.FindControl("ControlName");
试试这个...
try this ...
ContentPlaceHolder mpContentPlaceHolder;
TextBox mpTextBox;
mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
if(mpContentPlaceHolder != null)
{
mpTextBox = (TextBox) mpContentPlaceHolder.FindControl("TextBox1");
if (mpTextBox != null)
{
mpTextBox.Text = "TextBox found!";
}
}
// Gets a reference to a Label control that not in
// a ContentPlaceHolder
Label mpLabel = (Label) Master.FindControl("masterPageLabel");
if (mpLabel != null)
{
Label1.Text = "Master page label = " + mpLabel.Text;
}
Google是免费的.了解如何使用它.
Google is free. Learn how to use it.
ContentPlaceHolder mpContentPlaceHolder;
TextBox mpTextBox;
//there is slit diff in bellowed line that is There should be this instead of master
// mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
mpContentPlaceHolder = (ContentPlaceHolder)this.FindControl("ContentPlaceHolder1");
if(mpContentPlaceHolder != null)
{
mpTextBox = (TextBox) mpContentPlaceHolder.FindControl("TextBox1");
if (mpTextBox != null)
{
mpTextBox.Text = "TextBox found!";
}
}
// Gets a reference to a Label control that not in
// a ContentPlaceHolder
Label mpLabel = (Label) Master.FindControl("masterPageLabel");
if (mpLabel != null)
{
Label1.Text = "Master page label = " + mpLabel.Text;
}
这篇关于要o访问母版页中的内容页控件怎么可能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!