0

I have the following code:

<link rel="stylesheet" type="text/css" href="<%= GlobalVar.BasePath %>/css/style.css" />

the c# code is rendered as text, but the following works:

<link rel="stylesheet" type="text/css" href=<%= "\"" + GlobalVar.BasePath %>/css/style.css" />

Just curious, what is the solution to render it normally like I did in the first example?

I just want to know why it renders as text.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Novak
  • 2,760
  • 9
  • 42
  • 63
  • Could you paste what is rendered in each case? – pfries Apr 28 '12 at 16:56
  • This question can be linked to this :[http://stackoverflow.com/questions/5603086/problem-in-expression-tag-to-bind-string-variable][1] [1]: http://stackoverflow.com/questions/5603086/problem-in-expression-tag-to-bind-string-variable – Rohith Nair Apr 28 '12 at 17:13
  • Please don't prefix your titles with "C# ASP.NET" and such. That's what the tags are for. – John Saunders Apr 28 '12 at 17:22

1 Answers1

1

Not sure why you're getting the issues, but you could solve the problem of using the GlobalVar by programmatically adding the css link:

protected void Page_Init(object sender, EventArgs e)
{ 
    HtmlLink css = new HtmlLink();
    css.Href = String.Format("{0}/css/style.css", GlobalVar.BasePath);
    css.Attributes["rel"] = "stylesheet";
    css.Attributes["type"] = "text/css";
    css.Attributes["media"] = "all";
    Page.Header.Controls.Add(css); 
}
Simon Martin
  • 4,203
  • 7
  • 56
  • 93