Thank you for that information. I think the basic scenario of my situation
is that I am using Master/Content pages, and the CSS class I want will only
be used in one content page. However, the CSS class will not always be the
same, so it must be generated, so I cannot place it in the HTML or an
external stylesheet like you normally would.
--
Nathan Sokalski
(e-mail address removed)
http://www.nathansokalski.com/
I am not talking about the Style property of a web server control, I am
talking about a Web.UI.WebControls.Style object, which does not have an
Add
method. You seem to have the Style object confused with the
CssStyleCollection object. These two object can be easy to confuse because
the Style property is not an instance of the Style class. Any other
suggestions?
--
Nathan Sokalski
(e-mail address removed)://
www.nathansokalski.com/
- Show quoted text -
Ok, I misread your post slightly. Can I take it then that you are
trying encapsulate a set of css styles in an instance of
System.Web.UI.WebControl.Style class so it can be applied to any
control without having to set the properties for each control
individually? i.e. you are trying to emulate the way css "class"
attributes work without having to access the <style> tags.
I have tested the following which works OK
(note that System.Web.UI.WebControl namespace is within scope)
Style s = new Style();
s.Font.Size = FontUnit.Parse("2em");
s.ForeColor = System.Drawing.Color.Blue;
Label1.ControlStyle.CopyFrom(s);
Is that anything like what you are trying to do?
Note also that the Style object does not encapsulate all possible css
styles, e.g. it doesn't handle things like "margin" or "padding"
However the Style object does have a CssClass property that can be
used in the same way as those illustrated above except that the
definition of the css class has to reside in markup in the usual way.
Is there any reason why you can't use themes for all this, which allow
the selected application of both Skin and CSS style sheets, and can be
applied at page level using the @page directive (including content
pages) and hence at control level with css classes and Skin IDs?