how does Style class work?

T

terrorix

I have create Style class instance and set up properties like this:

Style st = new Style();
st.BackColor = Color.Black;
st.BorderColor = Color.White;
st.BorderStyle = BorderStyle.Solid;
st.BorderWidth = new Unit(1, UnitType.Pixel);

string styleStr = string.format("this.style.cssText='{0}', st.ToString());

cell.Attributes.Add("onmouseover", styleStr);


But st.ToString() seems to always return "" (string.empty). I want to return something like 'background-Color=Black; ... " text.

How the Style() class work and how i can do what i want?
 
T

terrorix

Eliyahu said:
I see you want to apply the style on client side. The easiest way of doing
this is like this:

1. Attach the style "MyStyle" to your page, either in the page header or in
a separate file.
2. cell.Attributes.Add("onmouseover", "className='MyStyle'");

Eliyahu

and then change className property on the client side.

return something like 'background-Color=Black; ... " text.


I know i can do this like you wrote. But i creating web custom control. I have properties like:
HotTrack_BackColor
HotTrack_BorderColor
HotTrack_BorderStyle
HotTrack_BorderWidth

and i want to setup these custom properties to control as "this.style.cssText='...'".

Anyway how can i use Style class manually ?
 
T

terrorix

Eliyahu said:
Doesn't look to me like the Style class is good for your task. It is not
intended for this sort of use. Just go through all your style properties and
make a style string out of style attributes like

String.Format("background-color:{0}", HotTrack_BackColor.ToString());

Eliyahu


I using this technique but i want know if it is another way to the this, more clear.

thanx again.
 
E

Eliyahu Goldin

I see you want to apply the style on client side. The easiest way of doing
this is like this:

1. Attach the style "MyStyle" to your page, either in the page header or in
a separate file.
2. cell.Attributes.Add("onmouseover", "className='MyStyle'");

Eliyahu

and then change className property on the client side.
terrorix said:
I have create Style class instance and set up properties like this:

Style st = new Style();
st.BackColor = Color.Black;
st.BorderColor = Color.White;
st.BorderStyle = BorderStyle.Solid;
st.BorderWidth = new Unit(1, UnitType.Pixel);

string styleStr = string.format("this.style.cssText='{0}', st.ToString());

cell.Attributes.Add("onmouseover", styleStr);


But st.ToString() seems to always return "" (string.empty). I want to
return something like 'background-Color=Black; ... " text.
 
E

Eliyahu Goldin

Doesn't look to me like the Style class is good for your task. It is not
intended for this sort of use. Just go through all your style properties and
make a style string out of style attributes like

String.Format("background-color:{0}", HotTrack_BackColor.ToString());

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top