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
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