Home All Groups Group Topic Archive Search About

Using a Stylesheet in a User Control

Author
22 May 2005 12:04 AM
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.
--
Nathan Sokalski
njsokal***@hotmail.com
http://www.nathansokalski.com/

Author
22 May 2005 12:30 AM
Smithers
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


Show quoteHide quote
"Nathan Sokalski" <njsokal***@hotmail.com> wrote in message
news:%23H8QiHmXFHA.2664@TK2MSFTNGP15.phx.gbl...
>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.
> --
> Nathan Sokalski
> njsokal***@hotmail.com
> http://www.nathansokalski.com/
>
Author
22 May 2005 7:16 PM
EJD
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