Q: Why ViewState a Style object???

S

Sky Sigal

I guess my question is:

"Even if all the docs talk about making CompositeControls that serialize their multiple Style
objects into the ViewState object -- is there any reason that you can think of? Or can I safely get
rid of it?"

Let me explain:

It just sort of struck me 10 minutes ago that it might be time for me to requestion/confirm
something that I have been taking for granted -- but maybe I shouldn't..?

The question is: Why are we ViewStating/Serializing/Sending Style objects and round tripping them to
the client ? I know that sounds like a dumb question ...and frankly
I wouldn't care that much for the lost bandwidth for most of my controls -- but the one I am working
on currently has 5 or 6 views -- each with 5 or 6 Styles that could be used.
Serializing that whole thing is ...potentially huge.

And for what gain?


Consider a simple control
<CC:SomeControl style='border:solid 1px red;color:BLUE;font-family:Verdana;' Text=""/>

Assuming that somwhere on th page a button is clicked that we then decide to set the control's text
color to RED....Well...according to the net documentation I have I would be serializing the whole
Style--and sending it to the client just to track that.

Whereas
Render(){
if (ViewState["Clicked"]!=null){
MyControl.ForeColor=Color.Red;
}
}

would have done the same thing without sending all that weight to the client.


What's your opinion?
 
T

Teemu Keiski

Well,

you could also set style property individually, if that's what you mean.

MyControl.Style["color"]="red";

or the second approach is just by manipulating style attributes via
Attributes collection.

And to your original question, it of coiurse depends what else you have in
the Style that gets rendered. When you set ForeColor property, you are
setting actually your control's Style object's one property. ForeColor on
web control maps to ControlStyle.ForeColor and ControlStyle is the main
style object (of type System.Web.UI.WebControls.Style) which contains all
the style properties. So when there is something in the Style, that
something gets rendered.

If I misunderstood your question, please correct me, and I'll try to help
you with your issue.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke



Sky Sigal said:
I guess my question is:

"Even if all the docs talk about making CompositeControls that serialize their multiple Style
objects into the ViewState object -- is there any reason that you can think of? Or can I safely get
rid of it?"

Let me explain:

It just sort of struck me 10 minutes ago that it might be time for me to requestion/confirm
something that I have been taking for granted -- but maybe I shouldn't..?

The question is: Why are we ViewStating/Serializing/Sending Style objects and round tripping them to
the client ? I know that sounds like a dumb question ...and frankly
I wouldn't care that much for the lost bandwidth for most of my
controls -- but the one I am working
on currently has 5 or 6 views -- each with 5 or 6 Styles that could be used.
Serializing that whole thing is ...potentially huge.

And for what gain?


Consider a simple control
<CC:SomeControl style='border:solid 1px
red;color:BLUE;font-family:Verdana;' Text=""/>
Assuming that somwhere on th page a button is clicked that we then decide to set the control's text
color to RED....Well...according to the net documentation I have I would be serializing the whole
Style--and sending it to the client just to track that.

Whereas
Render(){
if (ViewState["Clicked"]!=null){
MyControl.ForeColor=Color.Red;
}
}

would have done the same thing without sending all that weight to the client.


What's your opinion?
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top