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

2
  • Try to use the full namespace ie. MyProgram.MyClass.DefaultURL Commented Jun 25, 2018 at 11:20
  • 1
    why does it have to be static? Commented Jun 25, 2018 at 11:22

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.