简体   繁体   中英

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

 <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."

Use this solution:

public string DefaultURL { get { return DefaultURL ; } }

UPDATE: It can also be declared as protected , as stated in the comments below.

Then, to call it on the ASPX side:

<%=DefaultURL%>

Note that this won't work if you place it on a server tag attribute. For example:

<asp:Label runat="server" Text="<%=DefaultURL%>" />

This isn't valid. This is:

<div><%=DefaultURL%></div>

Refer this Link Which is more Helpfull you will find the whole example also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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