Dynamically add Style Link to header of html

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

Is there a way to add a LINK rel="stylesheet" href="StyleSheet1.css"
type="text/css"> tag to the header of each page at run time, rather than
having to copy and paste it into the html view of every new form as we create
them?

I would use a base page probably, just not sure how to add the code and get
it into the header section of the outgoing html

Thanks
Jeff
 
Hi,

In 2.0 you can use Master Pages:

ASP.NET Master Pages Overview
http://msdn2.microsoft.com/en-us/library/wtxbf3hh.aspx

In previous framework versions add a runat=server attribute in the head tag:

<head runat="server" id="header"></head>

You can add a literal control in the code-behind:

private HtmlGenericControl header;

void Page_Load(object sender, EventArgs e)
{
header.Controls.Add(new LiteralControl(@"
<link rel=""stylesheet"" type=""text/css"" src=""" + cs1+ @""">
<link rel=""stylesheet"" type=""text/css"" src=""" + cs2 + @""">"
));
}

(Note: I didn't test the code so watch for typos)
 
Back
Top