views:

1352

answers:

3

How can I get the value of a style defined in a CSS class?

The markup has:

CssClass="grdTextBox" Text="aaaaaaaabbbbbbbccccccc"

The CSS style is:

.grdTextBox {FONT-SIZE: 12px; FONT-FAMILY: verdana; }

The .cs file has:

string cssClass = txtComments.CssClass;
Response.Write(" cssClass is : " + cssClass);

How can I find the value for font size or font family from code behind?

I can find them if they are in a style tag or if they are attributes of the text box. But how can you find the values if they are defined in a CSS class?

+4  A: 

You don't. For lack of a real explanation, CSS is a client side technology. The styles in the .css file aren't directly associated with the html element until the browser renders it.

Al W
A: 

You cannot do it.

The styles you declare in ASPX are merged to the output but it is not visible in code behind as far as I know.

Only if you add another styles to the collection like MyControl.Style.Add ("font-size", "12px") then you will have it there.

User
A: 
Me.Menu.Style("margin-top") = "170px"

You can change it if you want to use inline style otherwise you can write your own CSS type object to manipulate CSS.

Actually you can build a library like that so that people can download and contribute,just saying.

Braveyard