Re: ViewState Question
From: Andy Smith (f00_at_foo.com)
Date: 03/10/04
- Next message: Mark Olbert: "Persisting Events in WebControls"
- Previous message: Mark Olbert: "ViewState Question"
- In reply to: Mark Olbert: "ViewState Question"
- Next in thread: Mike Moore [MSFT]: "RE: ViewState Question"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 9 Mar 2004 21:46:28 -0700
here's a simple example control that has a custom style.
public class MyControl : WebControl {
private Style otherStyle;
[
DesignerSerializationVisibility( DesignerSerializationVisibility.Content ),
NotifyParentProperty( true ),
PersistenceMode( PersistenceMode.InnerProperty ),
]
public Style OtherStyle {
get {
if ( otherStyle == null ) {
otherStyle = new Style();
if ( IsTrackingViewState ) {
((IStateManager)otherStyle).TrackViewState();
}
}
return otherStyle;
}
}
protected override void LoadViewState( Object savedState ) {
if ( savedState = null ) {
base.LoadViewState( null );
return;
}
Object[] myState = (Object[])savedState;
if ( myState.Length != 2 ) {
throw new ArgumentException("Invalid ViewState");
}
base.LoadViewState( myState[0] );
if ( myState[1] != null ) {
((IStateManager)OtherStyle).LoadViewState( myState[1] );
}
}
protected override Object SaveViewState() {
Object[] myState = new Object[2];
myState[0] = base.SaveViewState();
myState[1] = ( otherStyle != null ) ?
((IStateManager)otherStyle).SaveViewState() : null;
for ( int i = 0; i < 2; i++ ) {
if ( myState[i] != null ) {
return myState;
}
}
return null;
}
protected override void TrackViewState() {
base.TrackViewState();
if ( otherStyle != null ) {
((IStateManager)otherStyle).TrackViewState();
}
}
}
__
Andy Smith
"Mark Olbert" <mark@arcabama.com> wrote in message
news:cais40d26khjkoah3dgphc1sfhaf52lf7q@4ax.com...
> Okay, I give up... how do you get a customized descendant of Style to
persist through ViewState??? I
> tried following the online docs, but I'm obviously doing something wrong.
Here're the overrides I
> created in my WebControl class:
>
> protected override object SaveViewState()
> {
> object baseState = base.SaveViewState();
> object closedStyleState = (closedStyle != null) ? ((IStateManager)
> closedStyle).SaveViewState() : null;
> object[] state = new object[2];
> state[0] = baseState;
> state[1] = closedStyleState;
>
> return state;
> }
>
> protected override void LoadViewState( object savedState )
> {
> if( savedState != null )
> {
> object[] state = (object[]) savedState;
> if( state[0] != null ) base.LoadViewState(state[0]);
> if( state[1] != null ) ((IStateManager)
closedStyle).LoadViewState(state[1]);
> }
> }
>
> protected override void TrackViewState()
> {
> base.TrackViewState();
> if( closedStyle != null ) ((IStateManager) closedStyle).TrackViewState();
> }
>
> When I break on the debugger in SaveViewState(), the closedStyle property
(which is a grandchild of
> Style) shows that it's been initialized (i.e., the BackColor is set to
Red, as per my test webpage).
>
> But the line that should be creating closedStyleState just returns...
null.
>
> Suggestions?
>
> - Mark
- Next message: Mark Olbert: "Persisting Events in WebControls"
- Previous message: Mark Olbert: "ViewState Question"
- In reply to: Mark Olbert: "ViewState Question"
- Next in thread: Mike Moore [MSFT]: "RE: ViewState Question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|