0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
shami sheikh
  • 552
  • 3
  • 13
  • 26

1 Answers1

1

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Hitesh Anshani
  • 1,499
  • 9
  • 19