Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Composite Control - Viewstate management for complex properties

Reply
Thread Tools

Composite Control - Viewstate management for complex properties

 
 
Matt T.
Guest
Posts: n/a
 
      09-07-2004
I have seen several composite control examples where LoadViewState and
SaveViewState are overloaded to track viewstate on complex objects
such as styles, but I cannot find anything that tells me why I need to
do this.

Can someone tell me why is this code not sufficient for Viewstate
management?

if (style == null)
style = new Style();

((IStateManager) style).TrackViewState();

return style;
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      09-11-2004
Hi,

because in those scenarios when those methods are not overridden, the
container control's ViewState collection is passed as argument to the Style
object (its constructor) which means that the Style automatically has where
to put the state (ViewState collection handles it right away). And note that
this is with the default style of the control (ControlStyle) because the
ViewState collection of the control can be shared with one Style object and
by default it is the ControlStyle/default style.

So, if you have additional style for your control, to save and load it,
you'd need override SaveViewState and LoadViewState (as well as
TrackViewState)

And in case of the Style property, the code should be something like:

public Style MyStyle
{
get
{
if(style==null)
{
style=new Style();
if(IsTrackingViewState)
{
((IStateManager) style).TrackViewState();
}
}
return style;
}
}

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



"Matt T." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> I have seen several composite control examples where LoadViewState and
> SaveViewState are overloaded to track viewstate on complex objects
> such as styles, but I cannot find anything that tells me why I need to
> do this.
>
> Can someone tell me why is this code not sufficient for Viewstate
> management?
>
> if (style == null)
> style = new Style();
>
> ((IStateManager) style).TrackViewState();
>
> return style;



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Composite Control Viewstate stored properties fromclientside Javascript Andy ASP .Net 2 04-09-2010 04:50 PM
complex properties (font) on composite controls Gentian Hila ASP .Net Building Controls 2 01-19-2006 10:53 AM
Composite Control and accessing complex properties of child controls - C# VS2005 Paul Yanzick ASP .Net Building Controls 4 01-09-2006 01:11 AM
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM



Advertisments