How to Dynamically Link CSS file to an ASPX Page?

  • Thread starter Thread starter Jeremy
  • Start date Start date
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.
 
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
---------@
 
Back
Top