473,772 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7257
"Michael Albanese" <ma*******@ci.s tamford.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.Strin gWriter sw = new System.IO.Strin gWriter();

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

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

if (Page.IsPostBac k)
{
System.IO.Strin gReader sr =
new System.IO.Strin gReader((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/
vbconChoosingSe rverStateOption .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
3199
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp The problem I am having is that the data in the custom datagridcolumn is not saved to viewstate and after postback, the column does not contain data.
2
1628
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 the next page. But it keeps the original quantity I added to the viewstate. Where can i code this to post the correct quantity. Here is the code-behind I use. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)...
3
1829
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 '...populate DptList viewstate("Dept01") = DptList DptList.Clear()
3
1556
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 I would like to try by saving the view state to the server if this can speed up the access to these heavy pages. Could somebody give me a working example on saving the viewstate to the server written in VB. Thanks
4
4264
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 records and each record had 10 columns, how much extra cost is involved in saving that vs, a custom object with 10 get/set properties in a ArrayList holding 1000 instances of the object with the same data?
3
4573
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 set textboxes, radio buttons, etc - that viewstate is fine. Then I have a linkbutton that does a Server.Transfer over to Page2.aspx. When I Server.Transfer back to Page1.aspx, the viewstate info is lost. I ran across another example of this last...
5
246
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 pages. For example: page1.aspx accepts a users's name, age and gender, instantiated the new class and redirects to page2.aspx
0
4818
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 objects. For the purposes of this discussion, the objects define a Customer, and have an id and a name. I want to sort these customers by id or by name in ascending and descending order. Here is what I did to make it work.
1
1824
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 example, if I have a page with some date controls so I can choose a date range and postback the page. It then displays results based on that date range. When I leave the page for another page, I would like to have the Previous Page link take them...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.