473,287 Members | 3,228 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,287 software developers and data experts.

ViewState: Save & Load From database

Hello all!

I'm creating a web site in ASP.NET (VB.NET). One of the requirements was to
allow users to create orders going through several steps. A must have is to
have an option to save the work in any phase (any step) and to be able to
continue later.

My idea was to create several pages as steps (no, wizard control is not
suitable for several reasons) and to allow users to save any step to the
database, that is, a ViewState of the page (and page id) to the database.

I created a special Page class that overrides
LoadPageStateFromPersistenceMedium, SavePageStateToPersistenceMedium,
DeterminePostBackMode. Saving works great! The loading part sucks.

I have one textbox control for testing and cannot load text to it from saved
viewstate no matter what. Need help, big time.
Thanks!

Here's the code from my special Page class:

Imports Microsoft.VisualBasic

Public Class SaveStatePage
Inherits System.Web.UI.Page

Public MeSave As Boolean
Protected Overrides Function LoadPageStateFromPersistenceMedium() As
Object
If Me.Request.QueryString("IDsession") <> "" Then
Return Me.LoadSession()
Else
Return MyBase.LoadPageStateFromPersistenceMedium()
End If

End Function
Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal state As
Object)
If MeSave Then Me.SavePage(state)

MyBase.SavePageStateToPersistenceMedium(state)
End Sub

Protected Overrides Function DeterminePostBackMode() As
System.Collections.Specialized.NameValueCollection
If Me.Request.QueryString("IDsession") <> "" Then
Return Request.Form
Else
Return MyBase.DeterminePostBackMode()
End If
End Function

Protected Sub SavePage(ByVal state As Object)
Dim tmpLosFormatter As New LosFormatter
Dim tmpStream As New StringWriter

tmpLosFormatter.Serialize(tmpStream, state)

With New DataSetUitlityTableAdapters._viewstateTableAdapter
.InsertViewState(Session.SessionID, tmpStream.ToString, Now())
End With

End Sub

Protected Function LoadSession()
Dim tmpLosFormatter As New LosFormatter
Dim data As String

Dim tmpTable As DataSetUitlity._viewstateDataTable
Dim tmpReader As DataTableReader

data = " "
With New DataSetUitlityTableAdapters._viewstateTableAdapter
tmpTable =
..GetDataByIDsession(Me.Request.QueryString("IDses sion"))
End With
tmpReader = tmpTable.CreateDataReader()
If tmpReader.HasRows Then
tmpReader.Read()
Return
tmpLosFormatter.Deserialize(tmpReader.Item("ViewSt ate").ToString)
Else
Return tmpLosFormatter.Deserialize(data)
End If
End Function

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

End Sub
End Class
May 18 '06 #1
1 3002
contrary to popular belief, controls generally do not save their values in
viewstate. the browser posts the value, (and the value only). controls
generally store non value information it may need to process the postback
info.

for example the textbox needs to save the previous value, to implement the
onchange event, so the previous (render value) value is stored in
viewstate.it can then compare this to the postback value and tell if its
different.

generally to make you wizard work, you need to save the control values and
restore them, not the viewstate..

-- bruce (sqlwork.com)
"Irene" <Ir***@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hello all!

I'm creating a web site in ASP.NET (VB.NET). One of the requirements was
to
allow users to create orders going through several steps. A must have is
to
have an option to save the work in any phase (any step) and to be able to
continue later.

My idea was to create several pages as steps (no, wizard control is not
suitable for several reasons) and to allow users to save any step to the
database, that is, a ViewState of the page (and page id) to the database.

I created a special Page class that overrides
LoadPageStateFromPersistenceMedium, SavePageStateToPersistenceMedium,
DeterminePostBackMode. Saving works great! The loading part sucks.

I have one textbox control for testing and cannot load text to it from
saved
viewstate no matter what. Need help, big time.
Thanks!

Here's the code from my special Page class:

Imports Microsoft.VisualBasic

Public Class SaveStatePage
Inherits System.Web.UI.Page

Public MeSave As Boolean
Protected Overrides Function LoadPageStateFromPersistenceMedium() As
Object
If Me.Request.QueryString("IDsession") <> "" Then
Return Me.LoadSession()
Else
Return MyBase.LoadPageStateFromPersistenceMedium()
End If

End Function
Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal state As
Object)
If MeSave Then Me.SavePage(state)

MyBase.SavePageStateToPersistenceMedium(state)
End Sub

Protected Overrides Function DeterminePostBackMode() As
System.Collections.Specialized.NameValueCollection
If Me.Request.QueryString("IDsession") <> "" Then
Return Request.Form
Else
Return MyBase.DeterminePostBackMode()
End If
End Function

Protected Sub SavePage(ByVal state As Object)
Dim tmpLosFormatter As New LosFormatter
Dim tmpStream As New StringWriter

tmpLosFormatter.Serialize(tmpStream, state)

With New DataSetUitlityTableAdapters._viewstateTableAdapter
.InsertViewState(Session.SessionID, tmpStream.ToString, Now())
End With

End Sub

Protected Function LoadSession()
Dim tmpLosFormatter As New LosFormatter
Dim data As String

Dim tmpTable As DataSetUitlity._viewstateDataTable
Dim tmpReader As DataTableReader

data = " "
With New DataSetUitlityTableAdapters._viewstateTableAdapter
tmpTable =
.GetDataByIDsession(Me.Request.QueryString("IDsess ion"))
End With
tmpReader = tmpTable.CreateDataReader()
If tmpReader.HasRows Then
tmpReader.Read()
Return
tmpLosFormatter.Deserialize(tmpReader.Item("ViewSt ate").ToString)
Else
Return tmpLosFormatter.Deserialize(data)
End If
End Function

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

End Sub
End Class

May 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: theo | last post by:
Hi... I wish to extract the text content of an Xml file and assign it to DropDownList controls at runtime.I can get the Xml file text content into the DropDownList controls (Ex...if 5 Xml text...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
2
by: Bill Yeager | last post by:
I have a grid that I databind with a strongly typed dataset which contains thousands of records retrieved from a database. After the dataset is retrieved from the database, I place it in...
2
by: Jarod | last post by:
Hey I change backColor of linkButton in my Page_Load: lbDoSth.BackColor = Color.Red; But I have multiView on this page. On one of the views I have detailsView. When I add a new row a set...
6
by: sck10 | last post by:
Hello, I have applications that produce the following error when they have been open to long without activity. Is there any way to force a re-load of the page or go to another page if the page...
2
by: sck10 | last post by:
Hello, I have a web page that has a GridView and a FormView, each in its own panel. The GridView shows a list of records in a database. When a row in the GridView is selected the FormView...
2
by: Roshawn | last post by:
Hi, I've been fighting tooth and nail trying to handle clunky viewstate data. I happened to find some code that moves this data to the bottom of the page (to enhance spidering, of course). ...
0
by: nithagowda | last post by:
Hello, I have a DropDownList for source type and a panel for displaying TreeView based on the source type.. The problem is- if i select different source type drom ddlSrcType, other than the...
9
by: =?Utf-8?B?TUNN?= | last post by:
I'm sure the answer to my question varies depending on the situation, but I am looking for a general "best practice". If I have an asp.net application and I load certain data from a database,...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.