View Full Version : Dynamicaly build css rules

Mar 13, 2009, 8:05 AM
Hi everyone !

Does someone know how to accomplish this:


you can dynamicaly build css rules with predefined names and then use these dynamic css rules in renderer

Vladimir Shcheglov
Coolite Inc.

This is the answer for my thread "http://forums.ext.net/showthread.php?threadid=10001-4-1.aspx" but I donīt know how to "dynamicaly build css rules" from code behind.

Thanks in advance.

Mar 13, 2009, 11:01 AM
Check out your ScriptManager control; it has a method to apply new styles that you can predefine and use later in your page.

this.ScriptManager1.Style.Add("blackBG", "color: white !important; background-color:black !important;");

This will create an CSS style entry called blackBG that is accessible to everything. I hope this helps.


Mar 13, 2009, 12:07 PM
@mindcore1 - I'm not sure ScriptManager.Style.Add would work. I thought the .Style property was hidden. If it's not, it should be. The .Style property is a native asp.net property that we (purposely) ignore throughout the Toolkit. 

I'll take another look at the @fabiomarcos question.

Mar 13, 2009, 12:32 PM
Thanks, Geoffrey!

You are right, the ScriptManager would just ignore the new entry.

May 26, 2009, 4:42 PM
Sorry to bring this back but I have a similar question. On initial page load, I dynamically added a css style to the page. During an AjaxEvent, how can I modify that css style?

For example, I created a style called MyColor {background-color:Red;}. During an AjaxEvent, I want to change the color to black so all elements with that css class will be affected.

May 26, 2009, 4:53 PM

I think you need use

createStyleSheet and updateRule

If properly understood then updateRule can work with css rules defined in markup as well (I mean that createStyleSheet is not required for updateRule)

May 26, 2009, 5:00 PM
Hi Jacky,

It's best to start a new thread. Please post a cross link between the threads if you feel they are related.