代码之家  ›  专栏  ›  技术社区  ›  shami sheikh

无法访问aspx页中的变量

  •  0
  • shami sheikh  · 技术社区  · 6 年前

    我试着从后端使用变量。事实上,我正试图从现有的解决方案中复制解决方案。在旧的解决方案中运行良好,但在新的解决方案中,我无法访问代码隐藏变量。

    这是我的代码:

     public static string DefaultURL { get { return Global.URL; } }
    

    这是aspx页面

    <a href="<%= DefaultURL %>">
      <img src="../Content/img/logohome.png" class="img-responsive "       
      style="width: 111px;" />
    </a>

    但是变量 DefaultURL 给出一个错误,比如“当前上下文中不存在DefaultURL”。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Cœur Gustavo Armenta    6 年前

    使用此解决方案:

    public string DefaultURL { get { return DefaultURL ; } }
    

    更新: 它也可以被声明为 protected ,如下评论所述。

    然后,在aspx端称之为:

    <%=默认URL%>

    请注意,如果将其放在服务器标记属性上,则此操作将不起作用。例如:

    <ASP:标签RunAT=“服务器”文本=“& lt;%= Debug %& gt;”/gt;

    这是无效的。这是:

    <div><%=默认URL%></div>

    参考这个 Link 更有用的是你会发现整个例子也。