in

SharePoint University

Clean slate. Nothing but SharePoint.
Go, SharePoint!

how to apply css to custom web part?

Last post 09-10-2008 3:35 AM by gpoonam13. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-27-2008 3:33 AM

    how to apply css to custom web part?

    I've created a custom web part in visual studio 2005.

    i want to apply style sheet to this web part?

    how do i do this?

    where should i add reference for css in custom code?

  • 07-08-2008 8:16 AM In reply to

    Re: how to apply css to custom web part?

    All you need add a small code on the PreRender
    like:

     private void Style_PreRender(object sender,
       System.EventArgs e )
     {
        RegisterClientStyleSheetFile("_WPR_/style.css");
    }

    and on the constructor you need to add

    this.PreRender += new EventHandler(Style_PreRender);

    I hope it will help you,

    Roi Kolbinger
    Web: http://www.kwizcom.com
    Blog: http://kwizcom.blogspot.com/

    Filed under: , ,
  • 09-10-2008 1:55 AM In reply to

    Re: how to apply css to custom web part?

    Hi Roi,

        Thx for the post ...  it seems quite useful but Can  u decribe what does RegisterClientStyleSheetFile method  is doing

    and its definition. Thx in Advance

    Regards

    Abhishek Gupta

     

  • 09-10-2008 3:35 AM In reply to

    Re: how to apply css to custom web part?

     

    I used the following code: protected override void OnLoad(EventArgs e) { HtmlLink cssLink = new HtmlLink(); cssLink.Attributes.Add("type", "text/css"); cssLink.Attributes.Add("rel", "stylesheet"); cssLink.Attributes.Add("href", "/_layouts/1033/styles/custom.css"); this.Page.Header.Controls.Add(cssLink); //OR LiteralControl lc = new LiteralControl(); lc.Text = " .ms-customStyle{ padding: 5px 5px 5px 5px; color: blue; border-color:black} "; this.Page.Header.Controls.Add(lc); }
Page 1 of 1 (4 items)

Need SharePoint Training? Attend a SharePoint Bootcamp!
Forum content (c) original posters. Everything else (c) 2008 SharePoint Experts, Inc.