Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2007, 07:40 PM
Authorized User
 
Join Date: Aug 2003
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Persist DataSet in ViewState

This is for registering for swimming lesson sessions for the summer. The temporary (local on the client) table would hold one swimmer's registration for the summer (can't see how he could attend more than 4-5). Adds and deletes would be posted to the main database at the end of the session kind of like a shopping cart. The sessions would be like someone registering for a school semester on-line. Since only a half-dozen rows in the table would be involved it seemed possible to work with that underlying table since it was already bound to the GridView. I have never worked with a cache like a reply suggests but maybe that makes more sense.

A selection is made from another GridView and the row is added to the
underlying table of the first GridView. The ViewState of a GridView seems to work just fine when a SQL operation on the database on the server takes place and the DataSource is bound again, so a small, persisted working table bound to its own grid seems logical. However, its the working table between postbacks that collects the adds and deletes that's critical. Here's the abbreviated code which creates, saves and restores the ViewState:

Sub Page_Load
   If Not Page.IsPostBack Then
      'stmts to create dataset and table
      ViewState("aquatic") = dsAqua
   Else
      dsAqua = CType(ViewState("aquatic"), DataSet)
      dtLesson = dsAqua.Tables("lesson")
   End If
End Sub

Sub gridSessions_SelectedIndexChanged
   Dim rowSession As GridViewRow = gridSessions.SelectRow
   Dim drLesson As DataRow
   drLesson = dtLesson.NewRow()
   drLesson.Item("lessonid") = 0
   etc.
End Sub

In the page lifecycle postback events occur after load the event should act on the restored DataSet from Page_Load. But there is no schema from the DataTable returned. Maybe saving a DataSet in ViewState is not possible. But if you can keep track of a cache associated with a session and process it at the end maybe that makes more sense. I'll have to study the (Wrox etc.) books I have on it.
 
Old May 22nd, 2007, 07:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I would recommend approaching this problem from a different angle. Storing a whole dataset into viewstate could give you lots of performance problems. Remember that all the viewstate is being sent back and forth between the client browser and server. Is there a reason you want to do this? Wouldn't it be better to cache the data at the server?

Perhaps if you describe the problem you are trying to solve or what you are hoping to achieve we could offer a better solution.

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to persist Context.User across pages? musa BOOK: ASP.NET Website Programming Problem-Design-Solution 5 January 4th, 2008 12:07 AM
Persist Property Values In Controls. jahanzaib.attari ASP.NET 2.0 Basics 1 September 21st, 2007 09:19 AM
Problem with check persist KamalRaturi ASP.NET 2.0 Professional 0 September 23rd, 2006 07:12 PM
sessions wont persist bogins Beginning PHP 2 April 22nd, 2004 01:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.