<\/script>')

Problem in Expression tag for string variable binding

I bind the path, as in the link tag

<link rel="stylesheet" media="screen" href='<%= AbsRoot_Path%>UserAccountTemp/css/reset.css' /> 

but he looks like this ...

 <link rel="stylesheet" media="screen" href="&lt;%= ConfigurationManager.AppSettings[&quot;rootpath&quot;].ToString() %>UserAccountTemp/css/reset.css" /> 

and it works with script> tag.

what is the reason for this and what is the solution?

UPDATE

install AbsRoot_Path

in web.config

 <add key="rootpath" value="http://localhost:1259/WallProfile/"/> 

and set the value to AbsRoot_Path

 public string AbsRoot_Path = ConfigurationManager.AppSettings["rootpath"].ToString(); 
+2
source share
2 answers

EDIT: Okay, I'll be more specific here.

ASP.NET treats the <link> inside the <head> as server controls, even if you did not specify the runat="server" attribute there. Thus, you are actually setting the β€œhref” property of the server-side control, so you get such strange values ​​there. Therefore, a workaround could be to add the id property for <link> and access it on the server side:

 <link id='lnkStylesheet' rel="stylesheet" media="screen" /> protected void Page_Init(object sender, EventArgs e) { HtmlLink lnkStylesheet= (HtmlLink)Page.Header.FindControl("lnkStylesheet"); lnkStylesheet.Href = AbsRoot_Path + "UserAccountTemp/css/reset.css"; } 

or use the solution I gave in my original answer:

It seems you have defined the <link> tag inside the <head> , and ASP.NET does not allow server constructs to be used there. But there is a simple way for this: you can add the <link> program code (use the server control for this HtmlLink ):

 protected void Page_Init(object sender, EventArgs e) { HtmlLink myHtmlLink = new HtmlLink(); myHtmlLink.Href = AbsRoot_Path + "UserAccountTemp/css/reset.css"; myHtmlLink.Attributes.Add("rel", "stylesheet"); myHtmlLink.Attributes.Add("screen", "screen"); Page.Header.Controls.Add(myHtmlLink); } 

Also, defining the AbsRoot_Path variable as ConfigurationManager.AppSettings["rootpath"].ToString() bit redundant, as ConfigurationManager.AppSettings["rootpath"] already of type string .

+5
source

You must add runat = server if you want asp.net to evaluate expressions or just display when writing ... so try adding runat = server like this

 <link runat=server rel="stylesheet" media="screen" href='<%= AbsRoot_Path%>UserAccountTemp/css/reset.css' /> 
0
source

All Articles