【问题标题】:Pass a variable from Site.Master.cs to Site.Master将变量从 Site.Master.cs 传递给 Site.Master
【发布时间】:2011-03-29 15:35:32
【问题描述】:

我是 C# Web 开发的新手。请多多包涵。

我正在尝试在 Site.Master 中引用 Site.Master.cs 中的参数,以便在 Site.Master 页面中,我可以这样做:

<%
  if (someParam == true) {
%>

some HTML code

<%
 }
%>

参数 someParam 是我想从 Site.Master.cs 传递的参数。

谢谢!

【问题讨论】:

    标签: c# asp.net parameter-passing


    【解决方案1】:

    使用可见性至少“受保护”(非私有)的类级字段(或更好:属性)。

    【讨论】:

      【解决方案2】:

      您可以使用LiteralControl

      <asp:Literal ID="myControl" runat="server">
      // Some html here.
      </asp:Literal>
      

      然后在代码隐藏中 - 适当地设置 Visible 属性。

      【讨论】:

        【解决方案3】:

        按照下面的代码示例。

        Site.Master.cs

        protected bool someParam
        {
            get;
            set;
        }
        

        Site.Master 页面

        <%
          if (someParam) {
        %>
        
        some HTML code
        
        <%
         }
        %>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-02-15
          • 2015-10-30
          • 2013-10-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多