zoukankan      html  css  js  c++  java
  • 使用了母版页面中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比较麻烦,不知道有没有什么好办法

  • 相关阅读:
    全排列
    06-联系人管理(xib应用)
    单键模式
    在mac上截屏的几种方式
    05-Tom猫(UIImageView的简单运用)
    04-图片排列切换
    03-图片浏览器(plist的简单应用)
    02-动态创建按钮
    01-实现图片按钮的缩放、动画效果(block的初步应用)
    oracle 监听动态和静态的配置
  • 原文地址:https://www.cnblogs.com/yeagen/p/1346864.html
Copyright © 2011-2022 走看看