使用了母版页面中FindControl(包含多层嵌套母版时)
2008-12-03 16:39
253 查看
获取多层母版中的控件:
ContentPlaceHolder holder = (ContentPlaceHolder)Master.Master.FindControl("ContentPlaceHolder1");
ContentPlaceHolder holder2 = (ContentPlaceHolder)holder.FindControl("ContentPlaceHolder2");
TextBox txt_Test = (TextBox)holder2.FindControl("Test");
用户控件本身的控件调用:
((Label)this.FindControl("Label1")).Text = "123";
这里要注意的是无法用Page.FindControl来找到,要用this
在宿主界面上调用用户控件上的控件:
System.Web.UI.UserControl uc = (System.Web.UI.UserControl)Page.FindControl("WebUserControl1");
((Label)uc.FindControl("Label1")).Text = "123";
在含有母版的宿主界面上调用用户控件上的控件:
ContentPlaceHolder holder = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");
System.Web.UI.UserControl uc = (System.Web.UI.UserControl)holder.FindControl("WebUserControl1");
((Label)uc.FindControl("Label1")).Text = "123"
从A用户控件中设置B用户控件中的值:
System.Web.UI.UserControl uc = (System.Web.UI.UserControl)Page.FindControl("WebUserControl1");
((Label)uc.FindControl("Label1")).Text = "123";
总体感觉:有母版甚至于母版嵌母版的页面上findcontrol比较麻烦,不知道有没有什么好办法
ContentPlaceHolder holder = (ContentPlaceHolder)Master.Master.FindControl("ContentPlaceHolder1");
ContentPlaceHolder holder2 = (ContentPlaceHolder)holder.FindControl("ContentPlaceHolder2");
TextBox txt_Test = (TextBox)holder2.FindControl("Test");
用户控件本身的控件调用:
((Label)this.FindControl("Label1")).Text = "123";
这里要注意的是无法用Page.FindControl来找到,要用this
在宿主界面上调用用户控件上的控件:
System.Web.UI.UserControl uc = (System.Web.UI.UserControl)Page.FindControl("WebUserControl1");
((Label)uc.FindControl("Label1")).Text = "123";
在含有母版的宿主界面上调用用户控件上的控件:
ContentPlaceHolder holder = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");
System.Web.UI.UserControl uc = (System.Web.UI.UserControl)holder.FindControl("WebUserControl1");
((Label)uc.FindControl("Label1")).Text = "123"
从A用户控件中设置B用户控件中的值:
System.Web.UI.UserControl uc = (System.Web.UI.UserControl)Page.FindControl("WebUserControl1");
((Label)uc.FindControl("Label1")).Text = "123";
总体感觉:有母版甚至于母版嵌母版的页面上findcontrol比较麻烦,不知道有没有什么好办法
相关文章推荐
- 不同页面之间传递值(使用Page.PreviousPage.FindControl)
- Spring 架构下使用jstl在页面上展示map或者list(包括类型嵌套的数据)
- linux 使用find命令查找包含某字符串的文件
- Android中使用Handler以及CountDownTimer实现包含倒计时的闪屏页面
- 使用AngularJS来实现HTML页面嵌套的方法
- 微信小程序入门教程 - 列表渲染多层嵌套循环及wx:key的使用
- include 嵌套 重复 文件包含使用条件编译处理
- 微信小程序入门教程--列表渲染多层嵌套循环及wx:key的使用
- DataForm中包含TabControl控件,FindNameInContent方法无法获取未选中TabItem里的控件问题
- 使用 present 方法实现页面返回跳转(多层返回跳转)
- FindControl方法的使用
- eclipse中使用spring boot 入门开发(包含:与jsp页面和数据库交互,cmd打包运行war包)
- 微信小程序入门教程--列表渲染多层嵌套循环及wx:key的使用
- 微信小程序入门教程--列表渲染多层嵌套循环及wx:key的使用
- Delphi封装Mdi窗体到Dll并使用插件管理,tabControl制作多页面
- AngularJS使用ui-route实现多层嵌套路由的示例
- 使用FindControl出现未将对象引用设置到对象的实例 错误的解决办法
- js:iframe的使用及页面嵌套多个iframe时iframe和父页子页之间的调用
- DataList页面嵌套使用iframe导致IE进度条停不下一直处于Loading状态
- 母版页中使用FindControl,后台使用FindControl查找Span