Re: user control stylesheets

Discussion in 'ASP .Net' started by Michael Mckenzie, Apr 22, 2004.

  1. Jill, your user control can use the Page.RegisterClientScriptBlock
    method to register the stylesheet link with the page it is hosted on.
    A good place for this is in the User Control's OnInit() method, like
    so:

    protected override void OnInit(EventArgs e)
    {
    if( !this.Page.IsClientScriptBlockRegistered( "myStyleLink" ) )
    this.Page.RegisterClientScriptBlock( "myStyleLink",
    "<link rel=stylesheet href=css/someStyleSheet.css type=text/css
    />" );

    base.OnInit (e);
    }

    Then, just expose a property for the user of your control to enter the
    stylesheet path & filename. You can use that property and inject it
    into the filename above.

    Hope this helps,
    Mike


    "Jill Graham" <> wrote in message news:<>...
    > Hi,
    >
    > I have an asp .net page which includes several custom user controls.
    > Each user control has its own template (.ascx file)
    >
    > Now, I want my graphical people to be able to add a link to a stylesheet
    > file on top of the template file.
    > This link should then be included in the head section of the page.
    >
    > This means that the user control should pass the stylesheet link to the page
    > and the page should insert the stylesheet link into its head section.
     
    Michael Mckenzie, Apr 22, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JezB
    Replies:
    2
    Views:
    404
  2. Oleg Ogurok

    Re: Web User Controls And StyleSheets

    Oleg Ogurok, Jun 30, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    559
    Steven Cheng[MSFT]
    Jul 8, 2004
  3. Mad Scientist Jr
    Replies:
    0
    Views:
    646
    Mad Scientist Jr
    Mar 22, 2006
  4. Larry

    Stylesheets on web user controls

    Larry, Dec 11, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    185
    Jeffrey Tan[MSFT]
    Dec 12, 2003
  5. Thomas 'PointedEars' Lahn
    Replies:
    0
    Views:
    128
    Thomas 'PointedEars' Lahn
    May 1, 2004
Loading...

Share This Page