Using a Stylesheet in a User Control

  • Thread starter Thread starter Nathan Sokalski
  • Start date Start date
N

Nathan Sokalski

I have a user control that uses classes from a CSS Stylesheet. Because a
User Control does not have a <head> section, I do not know where to put a
link tag to link it to the stylesheet. If I manually place a a link tag in
the page that I use the User Control in it works fine, but is there a way to
have the control add this link tag for me when I insert the control? Thanks.
 
You can inject the link tag into the page that hosts the user control. You
could place a Literal control on the page, then set its .Text property to a
string containing the the link tag. You could do this at the same place in
your code where you insert the control.

-HTH
 
Hi,

The user control that I have in one of my projects looks like this in
the HTML:

<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="Header.ascx.cs" Inherits="MyProject.Header1"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<LINK href="MyProject.css" type="text/css" rel="stylesheet">

Although I do use the same css file for all of the pages in the
project, if I just add the UC to a blank page without adding it to the
webform as well, it seems to work fine... HTH.
EJD
 
Back
Top