PDA

View Full Version : Dynamicaly build css rules



fabiomarcos
Mar 13, 2009, 9:05 AM
Hi everyone !

Does someone know how to accomplish this:

Hi,

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.

mindcore1
Mar 13, 2009, 12:01 PM
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.

-MC

geoffrey.mcgill
Mar 13, 2009, 1: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.

mindcore1
Mar 13, 2009, 1:32 PM
Thanks, Geoffrey!

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

jchau
May 26, 2009, 5: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.

Vladimir
May 26, 2009, 5:53 PM
Hi,

I think you need use
http://extjs.com/deploy/dev/docs/?class=Ext.util.CSS


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)

geoffrey.mcgill
May 26, 2009, 6: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.