how does Style class work?

  • Thread starter Thread starter terrorix
  • Start date Start date
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?
 
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 ?
 
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.
 
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.
 
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
 
Back
Top