By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,312 Members | 1,265 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,312 IT Pros & Developers. It's quick & easy.

Saving objects in ViewState

P: n/a
Can you save objects a (custom class) to Viewstate and
then get them on a later page??

I have a custom class for an ASP.Net application that I
would like to make available across several web pages.

For example:

page1.aspx accepts a users's name, age and gender,
instantiated the new class and redirects to page2.aspx

page2.aspx accesses the custom class for the information
and takes some action based on defined business rules.

My application needs access to a defined set of data
across a series of five sepparate web pages, and i am
looking for the best way to do this.

Thanks,

Michael Albanese

Jul 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Michael Albanese" <ma*******@ci.stamford.ct.us> wrote in message
news:00****************************@phx.gbl...
Can you save objects a (custom class) to Viewstate and
then get them on a later page??

I have a custom class for an ASP.Net application that I
would like to make available across several web pages.


Why not use session state?

-- Alan
Jul 21 '05 #2

P: n/a
So long as your class can be serialized, you can put it in
Viewstate. However, Viewstate is not really optimized for
storing objects and session state is generally considered
a better solution.
-----Original Message-----
Can you save objects a (custom class) to Viewstate and
then get them on a later page??

I have a custom class for an ASP.Net application that I
would like to make available across several web pages.

For example:

page1.aspx accepts a users's name, age and gender,
instantiated the new class and redirects to page2.aspx

page2.aspx accesses the custom class for the information
and takes some action based on defined business rules.

My application needs access to a defined set of data
across a series of five sepparate web pages, and i am
looking for the best way to do this.

Thanks,

Michael Albanese

.

Jul 21 '05 #3

P: n/a
Hi Michael,

Thanks for your post. I agree with previous replies from Christopher and
Alan. In MSDN, there is code snippet which demonstrates saving/restoring a
dataset to/from view state.

//------------------code snippet--------------------
sqlDataAdapter1.Fill(dSet);
System.IO.StringWriter sw = new System.IO.StringWriter();

// Write the DataSet to the ViewState property.
dSet.WriteXml(sw);
ViewState["dSet"] = sw.ToString();

//**********************************************

if (Page.IsPostBack)
{
System.IO.StringReader sr =
new System.IO.StringReader((string)(ViewState["dSet"]));
dSet.ReadXml(sr);
}
//---------------------end of-------------------------------

Please kindly note that Session state and Application state are on the
Server side, while View state is on the client side. I strongly recommend
you the following MSDN article:

State Management Recommendations
http://msdn.microsoft.com/library/de...us/vbcon/html/
vbconChoosingServerStateOption.asp

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #4

P: n/a
Thanks for the feedback.

I have a working version of the app that uses session state and that
will be fine i guess.

I have printed the MSDN article and will read it today.

Thanks again

Michael


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #5

P: n/a
You are welcome! :-)

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.