B
Bill Biddy
I have search the newsgroups thoroughly and though I have seen several
posts about similar issues I have never seen one that clearly addresses
my problem.
My Control never Gets a LoadViewState Call!
I have a WebControl that is being created as an item template in a
databound templated control (DataList). Within my custom control I have
a complex state Type that wish to add to ViewState. The class that I am
adding to ViewState implements the IStateManager Interface and is
defined as:
//SessionBag contains a SortedList property named List
public class ViewStateBag : SessionBag, IStateManager
{
protected bool _IsTrackingViewState;
protected StateBag _viewstate;
public ViewStateBag()
{
_viewstate = new StateBag();
}
bool IStateManager.IsTrackingViewState
{
get
{
return this._IsTrackingViewState;
}
}
void IStateManager.LoadViewState(object savedState)
{
ArrayList a = new ArrayList();
ArrayList keys = (ArrayList)_viewstate["Keys"];
ArrayList values = (ArrayList)_viewstate["Values"];
for (Int32 x = 0; x < keys.Count; x++)
{
List.Add(keys[x], values[x]);
}
if (savedState != null)
((IStateManager)_viewstate).LoadViewState(savedState);
}
object IStateManager.SaveViewState()
{
if( (!((IDictionary)_viewstate).Contain("SkillsStateBag")) ||
(_viewstate.IsItemDirty("SkillsStateBag")))
{
_viewstate.Clear();
ArrayList keys = new ArrayList();
ArrayList values = new ArrayList();
foreach (DictionaryEntry d in List)
{
keys.Add(d.Key);
values.Add(d.Value);
}
_viewstate["Keys"] = keys;
_viewstate["Values"] = values;
}
_viewstate.SetItemDirty("Keys", true);
_viewstate.SetItemDirty("Values", true);
return ((IStateManager)_viewstate).SaveViewState();
}
void IStateManager.TrackViewState()
{
this._IsTrackingViewState = true;
((IStateManager)_viewstate).TrackViewState();
}
}
posts about similar issues I have never seen one that clearly addresses
my problem.
My Control never Gets a LoadViewState Call!
I have a WebControl that is being created as an item template in a
databound templated control (DataList). Within my custom control I have
a complex state Type that wish to add to ViewState. The class that I am
adding to ViewState implements the IStateManager Interface and is
defined as:
//SessionBag contains a SortedList property named List
public class ViewStateBag : SessionBag, IStateManager
{
protected bool _IsTrackingViewState;
protected StateBag _viewstate;
public ViewStateBag()
{
_viewstate = new StateBag();
}
bool IStateManager.IsTrackingViewState
{
get
{
return this._IsTrackingViewState;
}
}
void IStateManager.LoadViewState(object savedState)
{
ArrayList a = new ArrayList();
ArrayList keys = (ArrayList)_viewstate["Keys"];
ArrayList values = (ArrayList)_viewstate["Values"];
for (Int32 x = 0; x < keys.Count; x++)
{
List.Add(keys[x], values[x]);
}
if (savedState != null)
((IStateManager)_viewstate).LoadViewState(savedState);
}
object IStateManager.SaveViewState()
{
if( (!((IDictionary)_viewstate).Contain("SkillsStateBag")) ||
(_viewstate.IsItemDirty("SkillsStateBag")))
{
_viewstate.Clear();
ArrayList keys = new ArrayList();
ArrayList values = new ArrayList();
foreach (DictionaryEntry d in List)
{
keys.Add(d.Key);
values.Add(d.Value);
}
_viewstate["Keys"] = keys;
_viewstate["Values"] = values;
}
_viewstate.SetItemDirty("Keys", true);
_viewstate.SetItemDirty("Values", true);
return ((IStateManager)_viewstate).SaveViewState();
}
void IStateManager.TrackViewState()
{
this._IsTrackingViewState = true;
((IStateManager)_viewstate).TrackViewState();
}
}