473,406 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Saving objects in ViewState

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
5 7223
"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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
2
by: Gary Vidal | last post by:
I have a shopping cart webpage that shows a product and the Quantity they would like to order: When you click the link I want to take the quantity that they entered in the textbox and post that to...
3
by: Jim Corey | last post by:
I'm trying to save some ArrayLists to viewstate and then use them as DataSources for dropdownboxes. The code looks like this: 'DptList is a arraylist variable local to this procedure ...
3
by: Denis Georgievski | last post by:
I am optimizing my web application written in ASP/VB.NET 1.1. I have number of pages that have dropdown list server controls that contain large number of items. Before redesigning the data access...
4
by: John Kandell | last post by:
Hi, Would someone be able to shed some light on what is the cost of saving a DataTable to session vs saving a custom object of the same data. For example, let's say I had a DataTable with 1000...
3
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and...
5
by: Michael Albanese | last post by:
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...
0
by: rmgalante | last post by:
Hi, I've been experimenting with the ASP.Net GridView and encountered some interesting issues that I thought I would share. I have a page that loads a GridView with a generic collection of...
1
by: Jeff | last post by:
I need to place a "Previous Page" link on every page within my site and a simple javascript:history.back() will not work because I need it to capture the state of the page when I left it. For...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.