IDs and CSS
-
I am facing a bit of a problem with the IDs generated by the framework for HTML elements that exist within a user control or a web control that is added to the page dynamically. The framework goes and creates some kind of hierarchy and adds prefixes to the IDs. My question is how do you guys manage these when you want to create a unique CSS declaration for a specific element? For example, if I have a user control that generates a contact form, and I want to give to a textbox that exists within that contact form a unique style.
Excellence is not an act, but a habit!
Aristotle
-
I am facing a bit of a problem with the IDs generated by the framework for HTML elements that exist within a user control or a web control that is added to the page dynamically. The framework goes and creates some kind of hierarchy and adds prefixes to the IDs. My question is how do you guys manage these when you want to create a unique CSS declaration for a specific element? For example, if I have a user control that generates a contact form, and I want to give to a textbox that exists within that contact form a unique style.
Excellence is not an act, but a habit!
Aristotle
-
Easy way: assign the controls classes and in the CSS use class selectors instead of id selectors Hard way: emit CSS file dynamically using handlers
Yes, using class selectors is one of the solutions I have already thought. There are cases though when you actually need to use ID selectors. Not many but there are some... :) How about the dynamic CSS emition? Could you please point me to more info about this technique? Thanking you in advance.
Excellence is not an act, but a habit!
Aristotle
-
Yes, using class selectors is one of the solutions I have already thought. There are cases though when you actually need to use ID selectors. Not many but there are some... :) How about the dynamic CSS emition? Could you please point me to more info about this technique? Thanking you in advance.
Excellence is not an act, but a habit!
Aristotle
theJazzyBrain wrote:
How about the dynamic CSS emition? Could you please point me to more info about this technique?
http://www.codeproject.com/useritems/LocalizationHandler.asp[^] Not exactly the same thing, but demonstrates the basic strategy. A simpler, but less elegant solution would be to just use inline CSS, added to the page at runtime as a LiteralControl, in this case you don't need custom handlers.