如何给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");
}
還是有問題,依然不行。
先找到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");
}
還是有問題,依然不行。
相关文章推荐
- 【转】当PreviousPage.FindControl遇到MasterPage,如何查找控件
- 如何调用master Page中的控件 急急!!!
- masterpage中服务器端控件命名规则和如何用控件名取得document中的对象,用js动态设置控件事件和属性
- this.PreviousPage.FindControl遇到MasterPage,如何查找控件?
- 当PreviousPage.FindControl遇到MasterPage,如何查找控件?
- 在MasterPage中输出某个控件的Html文本时出现“类型“XX”的控件“XX”必须放在具有 runat=server 的窗体标记内”问题的解决
- MasterPage中找尋控件
- MasterPage嵌套及MasterPage中的控件和变量的访问
- .Net的MasterPage中的radiobuttonlist控件的javascript客户端取值
- 获取MasterPage内控件ID
- 如何让流程表单禁用选人控件,但可以通过代码赋值?
- SharePoint 2010 master page 控件介绍(3) :页面主体内容
- 内容页中操作MasterPage里的用户控件
- [导入]在自定义WebUserControl中访问PAGE/master/或其它控件中的对象
- MasterPage之超严重Bug——将导致窗体内带有回发事件的控件无法回发事件——以及解决方案
- 如何使用 MasterPage(注意母板页和子页面的执行顺序)
- 如何使用 MasterPage(注意母板页和子页面的执行顺序)
- ASP.Net访问母版页(MasterPage)控件、属性、方法及母版页中调用内容页,获取用户自定义控件里面的子控件的方法
- 使用Masterpage跟用户控件时,在指定页面的Head加载Javascript
- 如何打开Select a Master Page(选择母版页)对话框