ViewState: Save & Load From database

G

Guest

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("IDsession"))
End With
tmpReader = tmpTable.CreateDataReader()
If tmpReader.HasRows Then
tmpReader.Read()
Return
tmpLosFormatter.Deserialize(tmpReader.Item("ViewState").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
 
B

bruce barker \(sqlwork.com\)

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top