C
Chad McCune
I have some server controls I've built that store their properties in the
ViewState like good little controls However, When I set my "DataSource"
property of the controls to a DataSet or DataTable etc thats in the session,
it copies it into the ViewState. The DataGrid control doesnt seem to do
this if you do the following:
myDataGrid.DataSource = Session["mydatasource"];
How can I make my control do something similar...I'm including my custom
viewstate implementation
Thanks,
Chad McCune, MCSE, MCDBA
#region Custom State Management Implementation
protected override void LoadViewState(object savedState)
{
if (Context != null) Context.Trace.Write("AddressEditor", "LoadViewState
Begin");
object baseState = null;
object[] myState = null;
if (savedState != null)
{
myState = (object[])savedState;
if (myState.Length != 2)
{
throw new ArgumentException("Invalid view state");
}
baseState = myState[0];
}
base.LoadViewState(baseState);
// TODO: Load my viewstate properties here
if (Context != null) Context.Trace.Write("AddressEditor", "LoadViewState
End");
}
protected override object SaveViewState()
{
if (Context != null) Context.Trace.Write("AddressEditor", "SaveViewState
Begin");
object[] retVal = null;
object baseState = base.SaveViewState();
object _colState = null;
// TODO: Save my viewstate here
if ((baseState != null) || (_colState != null))
{
object[] savedState =new object[2];
savedState[0] = baseState;
savedState[1] = _colState;
retVal = savedState;
}
if (Context != null) Context.Trace.Write("AddressEditor", "SaveViewState
End");
return retVal;
}
protected override void TrackViewState()
{
if (Context != null) Context.Trace.Write("AddressEditor", "TrackViewState
Begin");
base.TrackViewState();
// TODO: Track my view state here
if (Context != null) Context.Trace.Write("AddressEditor", "TrackViewState
End");
}
#endregion
ViewState like good little controls However, When I set my "DataSource"
property of the controls to a DataSet or DataTable etc thats in the session,
it copies it into the ViewState. The DataGrid control doesnt seem to do
this if you do the following:
myDataGrid.DataSource = Session["mydatasource"];
How can I make my control do something similar...I'm including my custom
viewstate implementation
Thanks,
Chad McCune, MCSE, MCDBA
#region Custom State Management Implementation
protected override void LoadViewState(object savedState)
{
if (Context != null) Context.Trace.Write("AddressEditor", "LoadViewState
Begin");
object baseState = null;
object[] myState = null;
if (savedState != null)
{
myState = (object[])savedState;
if (myState.Length != 2)
{
throw new ArgumentException("Invalid view state");
}
baseState = myState[0];
}
base.LoadViewState(baseState);
// TODO: Load my viewstate properties here
if (Context != null) Context.Trace.Write("AddressEditor", "LoadViewState
End");
}
protected override object SaveViewState()
{
if (Context != null) Context.Trace.Write("AddressEditor", "SaveViewState
Begin");
object[] retVal = null;
object baseState = base.SaveViewState();
object _colState = null;
// TODO: Save my viewstate here
if ((baseState != null) || (_colState != null))
{
object[] savedState =new object[2];
savedState[0] = baseState;
savedState[1] = _colState;
retVal = savedState;
}
if (Context != null) Context.Trace.Write("AddressEditor", "SaveViewState
End");
return retVal;
}
protected override void TrackViewState()
{
if (Context != null) Context.Trace.Write("AddressEditor", "TrackViewState
Begin");
base.TrackViewState();
// TODO: Track my view state here
if (Context != null) Context.Trace.Write("AddressEditor", "TrackViewState
End");
}
#endregion