2

I am working with [Style] class in this way:

public class ServerControl1 : System.Web.UI.Control
{
    ....

    protected override void OnPreRender(EventArgs e)
    {
      Style wrapperStyle = new Style();

      wrapperStyle.BorderColor = BorderColor;
      ....
      ....

      this.Page.Header.StyleSheet.CreateStyleRule(wrapperStyle, null, key);

      .....
     }
}

How can I add such things as [line-height] or other?

1
  • why don't you simply give the control a css class? Commented Nov 5, 2012 at 12:27

1 Answer 1

2
wrapperStyle.Attributes.Add("class","wrapper_class");

In your CSS file

.wrapper_class {
    line-height:24px;
}

Edited:

wrapperStyle.Style.Add("line-height","24px");
Sign up to request clarification or add additional context in comments.

6 Comments

My approach is to make all css in one place (like Style class) and add it to header.I want to make independent control and not make manual css on aspx or css-files.
I have no idea why you'd want to do that, the overhead from adding another class and loading the CSS like that would have to be higher than adding an external CSS file...
I want every user can use my component without any custom working with css [he can set avaible properties to my component].
Edited answer to include code for adding individual styles. I still think it's too much overhead. Including a CSS sheet that the user could edit makes more sense.
pretty,but I cant find {Style} property in Style class
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.