0

I write it in aspx like this:

<link type="text/css" href='/theme<%=theme%>/top.css' rel="stylesheet" />

but result is this:

<link type="text/css" href="/theme&lt;%=theme%>/top.css" rel="stylesheet" />

surprising is that using in js is no problem.

2 Answers 2

3

It's because your link is inside a <head> tag which is runat server. The head tag is "smart", in that when it sees a <link> tag it lets you actually use the application relative path syntax: ~/. So if you do (inside your head tag):

<link href="~/Content/Site.css" rel="stylesheet" />

You'll see it will actually work (that is, it will expand the tilde to the proper location of your site), even though nowhere did you say runat server. The downside of course is when you DON'T want it to do that. :) Probably the easiest solution is to just manually build the tag yourself like this:

<%= "<link type=\"text/css\" href='/theme" + theme + "/top.css' rel=\"stylesheet\" />" %>
Sign up to request clarification or add additional context in comments.

Comments

0

You can't use expressions with <head runat="server"> instead you have to write following code in Page_Load event to insert <link/>

HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "Stylesheet");
link.Attributes.Add("href", "/theme" + theme + "/top.css");
Header.Controls.Add(link);

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.