Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ViewState: Save & Load From database

Reply
Thread Tools

ViewState: Save & Load From database

 
 
=?Utf-8?B?SXJlbmU=?=
Guest
Posts: n/a
 
      05-18-2006
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


 
Reply With Quote
 
 
 
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      05-18-2006
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" <> wrote in message
news:F2F840E1-8405-47E2-B4DA-...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Save contents of iframe from parent's save button user ASP .Net 1 04-04-2005 07:44 PM
word will not save or save as Alex B Computer Support 5 07-10-2004 05:23 AM
Save, Save As, Paste Phil Edwards Computer Support 1 06-27-2004 03:32 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57