2006-09-06

Inline Server Script in Header

Have you ever wanted to have inline script tags in your header control and add controls programatically. You will propably be getting an error about not being able to do this. This is especially true when you have a control that writes scripts into the header and then you also wish to have inline style sheets with the proper application path. The simple way to get around this problem is to wrap the inline scripts in an asp:PlaceHolder.

<html>
  <head runat="server">
    <title></title>
    <asp:PlaceHolder runat="server">
      <link href="<"%= SomeVariable %>/style.css" rel="stylesheet" type="text/css" />
    </asp:PlaceHolder>
  </head>
</html>


This way you can still add controls to the header by doing:
Page.Header.Controls.Add();

No comments: