简体   繁体   English

无法访问aspx页面中的变量

[英]Unable to access Variable in aspx page

I'm trying to use variable from back end. 我正在尝试从后端使用变量。 actually i'm trying to create copy the solution from the existing one. 实际上,我正在尝试从现有解决方案中复制解决方案。 In the old solution it works fine but in new solution I am unable to access the code behind variable. 在旧解决方案中,它可以正常工作,但在新解决方案中,我无法访问变量后面的代码。

Here is my code: 这是我的代码:

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

here is aspx page 这是aspx页面

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

But the variable DefaultURL gives an error like "The name DefaultURL does not exist in the current context." 但是变量DefaultURL会出现类似“名称DefaultURL在当前上下文中不存在”的错误。

Use this solution: 使用此解决方案:

public string DefaultURL { get { return DefaultURL ; } }

UPDATE: It can also be declared as protected , as stated in the comments below. 更新:也可以将其声明为protected ,如下面的评论所述。

Then, to call it on the ASPX side: 然后,在ASPX端调用它:

<%=DefaultURL%> <%= DefaultURL%>

Note that this won't work if you place it on a server tag attribute. 请注意,如果将其放置在服务器标签属性上,则将无法使用。 For example: 例如:

<asp:Label runat="server" Text="<%=DefaultURL%>" /> <asp:标签runat =“服务器”文本=“ <%= DefaultURL%>” />

This isn't valid. 这是无效的。 This is: 这是:

<div><%=DefaultURL%></div> <DIV> <(%)= DefaultURL%> </ DIV>

Refer this Link Which is more Helpfull you will find the whole example also. 请参考此链接,它对您有所帮助,您还将找到整个示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM