DataSources from Session??

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
 
M

MattC

My understanding, and I could be wrong, was that the DataSource property was
only used with the following DataBind() call, this then took the data from
the datasource and unpackaged it into the controls internal structure. It
is this data that is stored in the viewstate. So when you post back it can
reassemble itself from the viewstate info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top