My studying notebook

2008/08/18

ASP.NET 2.0 Content page add Css

8/18/2008 09:51:00 PM Posted by Unknown 1 comment
One of .NET framework 2.0 new important features. Master page, it allow you to create a consistent layout for the pages in your application. You can include Cascading Style Sheets link in master page for you all pages to use the same Cascading Style Sheets easily. But sometimes, you don't want content page to use Cascading Style Sheets inclued of Master page or you want add Cascading Style Sheets to a special page. How can we to do?

We can't add link Cascading Style Sheets syntax in ContentPlaceHolder of content page. So, we can use Htmllink control to add new attribuate.

protected void DynamicAddCss(string csspath) {
// Define an HtmlLink control.
HtmlLink myHtmlLink = new HtmlLink();
myHtmlLink.Href = csspath;
myHtmlLink.Attributes.Add("rel", "stylesheet");
myHtmlLink.Attributes.Add("type", "text/css");

// Add the HtmlLink to the Head section of the page.
Page.Header.Controls.Add(myHtmlLink);
}

// add Cascading Styles Sheet
DynamicAddCss("http://jquery.com/files/social/jquery.tabs-ie.css")

1 comment: