473,569 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
LoadPageStateFr omPersistenceMe dium, SavePageStateTo PersistenceMedi um,
DeterminePostBa ckMode. 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.Visua lBasic

Public Class SaveStatePage
Inherits System.Web.UI.P age

Public MeSave As Boolean
Protected Overrides Function LoadPageStateFr omPersistenceMe dium() As
Object
If Me.Request.Quer yString("IDsess ion") <> "" Then
Return Me.LoadSession( )
Else
Return MyBase.LoadPage StateFromPersis tenceMedium()
End If

End Function
Protected Overrides Sub SavePageStateTo PersistenceMedi um(ByVal state As
Object)
If MeSave Then Me.SavePage(sta te)

MyBase.SavePage StateToPersiste nceMedium(state )
End Sub

Protected Overrides Function DeterminePostBa ckMode() As
System.Collecti ons.Specialized .NameValueColle ction
If Me.Request.Quer yString("IDsess ion") <> "" Then
Return Request.Form
Else
Return MyBase.Determin ePostBackMode()
End If
End Function

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

tmpLosFormatter .Serialize(tmpS tream, state)

With New DataSetUitlityT ableAdapters._v iewstateTableAd apter
.InsertViewStat e(Session.Sessi onID, tmpStream.ToStr ing, Now())
End With

End Sub

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

Dim tmpTable As DataSetUitlity. _viewstateDataT able
Dim tmpReader As DataTableReader

data = " "
With New DataSetUitlityT ableAdapters._v iewstateTableAd apter
tmpTable =
..GetDataByIDse ssion(Me.Reques t.QueryString(" IDsession"))
End With
tmpReader = tmpTable.Create DataReader()
If tmpReader.HasRo ws Then
tmpReader.Read( )
Return
tmpLosFormatter .Deserialize(tm pReader.Item("V iewState").ToSt ring)
Else
Return tmpLosFormatter .Deserialize(da ta)
End If
End Function

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

End Sub
End Class
May 18 '06 #1
1 3029
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***@discussi ons.microsoft.c om> wrote in message
news:F2******** *************** ***********@mic rosoft.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
LoadPageStateFr omPersistenceMe dium, SavePageStateTo PersistenceMedi um,
DeterminePostBa ckMode. 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.Visua lBasic

Public Class SaveStatePage
Inherits System.Web.UI.P age

Public MeSave As Boolean
Protected Overrides Function LoadPageStateFr omPersistenceMe dium() As
Object
If Me.Request.Quer yString("IDsess ion") <> "" Then
Return Me.LoadSession( )
Else
Return MyBase.LoadPage StateFromPersis tenceMedium()
End If

End Function
Protected Overrides Sub SavePageStateTo PersistenceMedi um(ByVal state As
Object)
If MeSave Then Me.SavePage(sta te)

MyBase.SavePage StateToPersiste nceMedium(state )
End Sub

Protected Overrides Function DeterminePostBa ckMode() As
System.Collecti ons.Specialized .NameValueColle ction
If Me.Request.Quer yString("IDsess ion") <> "" Then
Return Request.Form
Else
Return MyBase.Determin ePostBackMode()
End If
End Function

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

tmpLosFormatter .Serialize(tmpS tream, state)

With New DataSetUitlityT ableAdapters._v iewstateTableAd apter
.InsertViewStat e(Session.Sessi onID, tmpStream.ToStr ing, Now())
End With

End Sub

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

Dim tmpTable As DataSetUitlity. _viewstateDataT able
Dim tmpReader As DataTableReader

data = " "
With New DataSetUitlityT ableAdapters._v iewstateTableAd apter
tmpTable =
.GetDataByIDses sion(Me.Request .QueryString("I Dsession"))
End With
tmpReader = tmpTable.Create DataReader()
If tmpReader.HasRo ws Then
tmpReader.Read( )
Return
tmpLosFormatter .Deserialize(tm pReader.Item("V iewState").ToSt ring)
Else
Return tmpLosFormatter .Deserialize(da ta)
End If
End Function

Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) 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
4879
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 tags then 5 dropdownlist controls each containing the 5 Xml text tags). Problem,when I save the user DropDownList selected items by means of a...
9
21631
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 the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario...
2
1119
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 viewstate. I need to do this because of the following: A user is allowed to check "x" amount of rows on the grid and submit those records (which causes a...
2
4226
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 Visible = false on this detailsView. And rebound appropriate gridView. Then I press the button and I have exception: Failed to load viewstate. The...
6
2925
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 has expired instead of getting the error? Thanks,
2
4481
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 Panel becomes visible. pnlGridViewSearchList pnlFormView The problem that I am having is that if I set the FormView Panel's
2
2464
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). Here it is: Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) Dim stringWriter As New System.IO.StringWriter() Dim...
0
1647
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 item which was selected in the previous run the following error message is displayed.. Please help me in this regard.. Failed to load viewstate. ...
9
2663
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, should I use ViewState to store and reload the data, or should I load the data from the database on each postback? Assume for the sake of this...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.