shami sheikh
shami sheikh

Reputation: 562

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

Upvotes: 0

Views: 326

Answers (1)

Hitesh Anshani
Hitesh Anshani

Reputation: 1549

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.

Upvotes: 1

Related Questions