【问题标题】:Accessing user control properties of master page inside a content page?访问内容页内母版页的用户控件属性?
【发布时间】:2012-10-12 06:41:52
【问题描述】:

在项目母版页中没有代码隐藏文件;在内容页面中,我需要阅读母版页内的用户控件属性。能否请您建议如何完成。

【问题讨论】:

    标签: c# asp.net .net vb.net


    【解决方案1】:

    在您的内容页面上试试这个

    YourControl YourControlObj = this.Master.FindControl("YourControl") as YourControl;
    

    【讨论】:

    • 他工作吗?我不这么认为..!当您在没有任何参考的情况下编写“YourControl”时,它会给出错误..!
    【解决方案2】:

    在母版页中 -

    <asp:TextBox Id="txt" />
    

    在内容页面中 -

    TextBox t = this.Master.FindControl("txt") as TextBox;
    t.Text = "Some Value";
    

    【讨论】:

    • Ritesh 它是一个用户控件。请指教
    • 我认为 UserControl 不会有任何区别。在母版页中 - &lt;my:UControl Id="uc" /&gt; 在内容页中 - UControl t = this.Master.FindControl("uc") as UControl; // You can use property now. 。
    【解决方案3】:

    看看有没有帮助

    Literal mpLiteral = (Literal) Master.FindControl("masterPageLiteralControlID");  
    

    【讨论】:

      【解决方案4】:

      这样做

      在母版页中

      <uc1:MyWebUserControl ID="myCtl" runat="server" ClientIDMode="Static" />
      

      在内容页面中(在代码后面)

      MyWebUserControl myWCtl  = this.Master.FindControl("myCtl") as MyWebUserControl;
      

      【讨论】:

      • 我已经尝试过,但它不起作用:在母版页中: 在内容页中:ShoppingCartControl myWCtl = this.Master.FindControl ("myCtl") 作为 ShoppingCartControl;它给出错误:“类型或命名空间不存在!任何想法?
      猜你喜欢
      • 2011-01-10
      • 1970-01-01
      • 2014-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-27
      相关资源
      最近更新 更多