一个页面A.aspx的母版页为master.master,现在想在a.aspx中对master.master中的一个用户控件left.ascx中的属性进行操作,应该怎么写?

解决方案 »

  1.   

    楼主实际在问两个问题:
    (1)如何访问master页面:用master.findcontrol(".....")
    (2)用户控件的类:用asp.进行,如果不明确,可以用gettype将它输出,这样你就看明白了。
      

  2.   

    比如我想通过a.aspx页面的代码,给master.master母板页中left.aspx用户组件的属性abc赋值,要怎么写呢?
      

  3.   

    在masterpage中定义方法:
    public void changelabel(string s1) 
        {
            this.Left1.label.Text = s1;
        }
    在内容页中加入引用:
    <%@ MasterType  virtualPath="~/MasterPage.master"%> 
    然后可以在内容页中直接调用masterpage中的公开方法.
      

  4.   

    在masterpage中定义方法:
    public void changelabel(string s1) 
        {
            this.Left1.label.Text = s1;
        }
    在内容页中加入引用:
    <%@ MasterType  virtualPath="~/MasterPage.master"%> 
    然后可以在内容页中直接调用masterpage中的公开方法.
      

  5.   

    有没有办法直接对left1中的控件进行操作呢?否则的话,我不是每个模板都要写上这些方法?
      

  6.   

    有没有搞错?为什么要引用页?那不是烦死了?
    以上代码在内容页中某按钮中
            Control ctltmp = null;
            Panel plTmp = null;        ctltmp = null;
            ctltmp = Page.Master.FindControl("plMstSeach");//plMstSeach是母版页中的控件ID
            if (ctltmp != null)
            {
                plTmp = (Panel)ctltmp;
                
                clsBase.funSetPanelPos(plTmp, 60, 50);//这个是对母版页中的Panel进行位置设定,plTmp就是母版页中的控件
                
            }
      

  7.   

    clsBase.funSetPanelPos是自己写的函数,不是系统哈,不要搞错了。
    对plTmp操作就是对你的控件的操作