I am trying to understand why a variable myUrlis out of context in the example below. What is the best way to deal with this situation? Are there any alternatives? The code is C # on an ASP.NET page.
myUrl
<% string myUrl = "http://www.website.com"; %> <ul class="footerLinks"> <li><a href="<%= myUrl %>/index.html">Home</a></li> </ul>
This is because it is <%=displayed before the script component. If you installed myUrlin the code behind ( Page_Loador the Initevent), it should enter the page as you expect. Obviously, also remove the variable declaration in the markup.
<%=
Page_Load
Init
First of all, your string variable should be publicly available at the class level.
public String myUrl
DataBind() method Page_PreRenderComplete:
DataBind() method
Page_PreRenderComplete
protected void Page_PreRenderComplete(object sender, EventArgs e) { DataBind(); }
<%= expressions .
<%= expressions