您的位置:首页 > 其它

如何给MASTERPAGE上的控件赋值。

2008-04-15 18:58 309 查看
在.net 2.0 中如果使用了masterPage,则不能像以前那样使用 FindControl,则需要使用如下方法

先找到ContentPlaceHolder,然后再找在这个ContentPlaceHolder中的你要找的控件

2//MasterPage 中的ContentPlaceHolder ID
3string masterPageContentPlaceHolderID = "";
4//在 masterPageContentPlaceHolderID 中所要找到的控件的 ID
5string m_strSetDataToID = "";
6//例如找 TextBox
7TextBox textBoxFind = (TextBox)this.Page.Master.FindControl(masterPageContentPlaceHolderID).FindControl(m_strSetDataToID);http://www.cnblogs.com/forward/articles/masterpage.html

ContentPlaceHolder mpContentPlaceHolder;
Label mpTextBox;
mpContentPlaceHolder =
(ContentPlaceHolder)Master.FindControl("home");
if (mpContentPlaceHolder != null)
{
mpTextBox = (Label)mpContentPlaceHolder.FindControl("ctl00_member_name");
if (mpTextBox != null)
{
mpTextBox.Text = "TextBox found!";
}
else
{
Response.Write("Label fdfd");
}
}
else
{
Response.Write("ContentPlaceHolder fdfd");
}

還是有問題,依然不行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐