Hi Marc,
From your description, you're wondering some best means to manage the
WebControl's custom properteis which will be persisted in ViewState.
Also, sometimes when we adjust those properties before the Page's
LoadViewState, they should be prevented from being override by the old data
retrieved in LoadViewState, yes?
I'm not sure whether there is any well-known pattern on this. As my own
opinion, I'll define my Control properties as the following style. The
public property is a wrapper of a private member variable which hold the
actual values and it is not directly accessing the ViewState, we read it
from and write into ViewState in our override LoadViewState and
SaveViewState. In addition, we can also define a certain value as the
default(empty) value of that property, thus, in the LoadViewstate, we can
determine whether to override the value or not in LoadViewState according
to whether the private variable's value is the empty value. How do you
think of this?
======================
......
private string title = null;
..............
public string Title
{
get
{
return title;
}
set
{
title = value;
}
}
protected override void LoadViewState(object savedState)
{
Triplet triplet = (Triplet)savedState;
if(title == null)
{
title = triplet.Second as string;
}
base.LoadViewState (triplet.First);
}
protected override object SaveViewState()
{
object baseState = base.SaveViewState ();
Triplet triplet = new Triplet();
triplet.First = baseState;
triplet.Second = title;
return triplet;
}
================================
If you have any other ideas, please feel free to post here.
Thanks & Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)