How to Dynamically Link CSS file to an ASPX Page?

J

Jeremy

Rather than hard-coding a reference to a css file in the HEAD of an aspx
page, like this...
<link rel="stylesheet" href="../css/admin.css" type="text/css">

How can I dynamically specify the particular css file to which the aspx page
is to link at runtime?

Thanks.
 
B

Brian Lowe

Jeremy said:
Rather than hard-coding a reference to a css file in the HEAD of an aspx
page, like this...
<link rel="stylesheet" href="../css/admin.css" type="text/css">

How can I dynamically specify the particular css file to which the aspx page
is to link at runtime?

You could do in the same way we did for classic ASP...
<link rel="stylesheet" type="text/css"
href='css/<%=Session("cssstylesheet")%>.css' >

Or you might prefer a purer ASP.Net model...
Insert a literal into the <head> of your HTML...
<asp:literal id="Literal1" runat="server"></asp:literal>

and then fill it in the Page_Load event...
Literal1.Text = String.Format("<link rel=""stylesheet"" type=""text/css""
src=""{0}"" />", myCssDoc)

Brian Lowe
---------@
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top