.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Change the css dynamically you can use following code snippet.

Posted By:Shweta Kulkarni       Posted Date: September 16, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Change the css dynamically you can use following code snippet..

Consider a scenario where you want to change the theme of the site which is total css based. So if you want to

1. Create Object of HtmlLink class.

System.Web.UI.HtmlControls.HtmlLink mycss = new System.Web.UI.HtmlControls.HtmlLink();

2. Change css as per drop down list selection.

string str=ddlTheme.SelectedValue.ToString();

//Drop down list contains theme name and css location.

3.Specify the path of the CSS.

mycss.Href = Server.MapPath(str);//Map the path for css.

4.Add attribute to css.

mycss.Attributes.Add("rel", "stylesheet");

mycss.Attributes.Add("type", "text/css");

5.Add CSS in page header as follow.



Shweta Kulkarni MCTS


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend