Faqs on asp.net,c#,vb.net and sqlserver2005

this blog covers all the Faqs related to .net technologies like asp.net,vb.net,c#.net,ajax,javascript and sqlserver2005.

Mar 11, 2008

change the CSS file dynamically in asp.net webpage

This is so that I can have an element ID duplicated in two different CSS files, and let my graphic designer tweak page designs without a developer having to change control IDs. There are CSS settings that will be specific to specific controls, so just doing everything with classes isn't really an option. Essentially, I want to be able to add the link href="Style1.css" type="text/css" rel="stylesheet" statement to the aspx, but change the css file name at runtime. The Page.StyleSheetTheme property looked promising, but it appears that I can't write to that. Anyone tried this before?

Something like this should work:


private void Page_Load(object sender, System.EventArgs e)

{
bool useScript1 = false;
string styleScript1 = "openangular barcket link rel=\"stylesheet\" type=\"text/css\" href=\"Style1.css\"/" close angular bracket;
string styleScript2 = "openangular barcket link rel=\"stylesheet\" type=\"text/css\" href=\"Style2.css\"/" close angular bracket;
if ( useScript1 )

this.RegisterClientScriptBlock("StyleScript", styleScript1);
else
this.RegisterClientScriptBlock("StyleScript", styleScript2);
}

Happy Programming

0 Comments:

Post a Comment

<< Home