|
-
Apr 16th, 2004, 10:21 AM
#1
Thread Starter
Lively Member
How to ensure the form user selections when user decides going back?
I have seen several web sites that in web forms user registration that consists with more than one page, when user presses the browser back button in order to go to the previous form filled page, seems that the previous page is rebuilt to ensure to fill all the form fields options according to the user selections. Seems that they rebuilt the page instead of rely on the user browser cache in order to maintain the options selected when user decides going back. Is this practice true? Or they are doing other things when the previous page is reloaded?
I have some dropdownlist form fields that are populated on client side, and these controls doesn’ t keep the original selections when the user decides to return to the form through the browser’s back button.
Any ideas?
Thanks
-
Apr 16th, 2004, 09:48 PM
#2
I wonder how many charact
A few things they could be doing:
1) storing the entered values into a proxy table in SQL, and relying on that table to refill fields.
2) Reposting to the same page, and hiding/showing panels on that page that relate to what step in the registration the user is in.
3) passing a dataset between the forms using viewstate, and retrieving the data related to the current page from the dataset.
On the last page, they use the fully-formed dataset and pass it to a procedure that completes the registration.
-
Apr 17th, 2004, 04:35 AM
#3
Thread Starter
Lively Member
Now I already store the form control values to a session variable, with a table into a dataset, and at the end of the process I Insert all the values in the database. Is this a good way of collecting the information during the process registration? Or there is another faster?
But I have to find out how to write a subroutine into the 'Page_Load' so that only is triggered if the form controls are stored in the current session table variables. To assign the session table variables values to the controls it' s easy, but I don' t know how to write the decision of triggering or not the subroutine according to whether the session table values are present or not. For instance:
Code:
Sub Page_Load (Sender As Object, E As EventArgs)
Dim UserDS As Data.DataSet = Session("UserData")
If (UserDS.Tables(0).rows(0).Item("City")) <> null Then
Control1.SelectedItem.Value = UserDS.Tables(0).rows(0).Item("City")
Control2.SelectedItem.Value = UserDS.Tables(0).rows(0).Item("Sate")
Control3.SelectedItem.Value = UserDS.Tables(0).rows(0).Item("Activity")
Control4.Text() = UserDS.Tables(0).rows(0).Item("Name")
Control4.Text() = UserDS.Tables(0).rows(0).Item("Surname")
...
End If
End Sub
The line highlighted in bold is not correct. Do you know how can I write the condition so that only the values will be filled if the control values of the current page are already stored on the current session variable? Because if the user arrives to the form for the first time I don’ t want (and I can’ t) to fill the controls with values from the current session.
Thank you,
Cesar
-
Apr 17th, 2004, 10:15 AM
#4
I wonder how many charact
Hmm....
How many fields are you storing? I see city, state, zip, activity, surname... it helps to know how many you have to store for this 'registration'... 20, 40, 50?
Because if its not an exuberant amount, I might be tempted to just store them in a dataset in viewstate, and pass that along via server.transfer, forward or back from the current page...
Also, if its only about 2 or 3 pages, you might be even better off using just one page.
Obviously, the registration in both scenarios above simply require a user hit a SUBMIT button, which resides on the last page, to trigger the database save.
-
Apr 17th, 2004, 11:35 AM
#5
Thread Starter
Lively Member
In total I have 30 fields, 15 per page more or less. and I prefer to use three pages (separate steps) for several reasons.
Because if its not an exuberant amount, I might be tempted to just store them in a dataset in viewstate, and pass that along via server.transfer, forward or back from the current page...
Would you mind teaching me this technique of to store the data fields in a dataset in viewstate, and that along via server.transfer, forward or back from the current page…? As well some information on the internet if it’ s possible.
As I said I need to know how to write the condition so that only the values will be filled if the control values of the current page are already stored in the current DataSet.....
Thank you
-
Apr 17th, 2004, 07:19 PM
#6
I wonder how many charact
Here you go, page 2 from my deceased vehicle wizard in my web app.. some importants part of it are bolded...
VB Code:
'this is the 2nd page in a series of 4
'but it illustrates how to handle
'data coming either from the first page (page 1)
'or page 3 (if the user hits previous on page 3)
Public Class VehicleWiz2
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents tbVIN As System.Web.UI.WebControls.TextBox
Protected WithEvents tbVehicleModel As System.Web.UI.WebControls.TextBox
Protected WithEvents tbVehicleYear As System.Web.UI.WebControls.TextBox
Protected WithEvents ddlVehicleMake As System.Web.UI.WebControls.DropDown
Protected WithEvents ddlVehicleStyle As System.Web.UI.WebControls.DropDown
Protected WithEvents ddlVehicleColor As System.Web.UI.WebControls.DropDown
Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
Protected WithEvents btnPrev As System.Web.UI.WebControls.Button
Protected WithEvents btnNext As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
[b]'this allows other pages to retrieve dataset from
'this page
Public ReadOnly Property Vehicle() As String
Get
Return Me.ViewState("vehicledata")
End Get
End Property
[/b]
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim _vehicledataset As New DataSet
If Not IsPostBack Then
[b] If TypeOf context.Handler Is VehicleWiz1 Then
'came from page 1
Dim v1 As VehicleWiz1 = DirectCast(context.Handler, VehicleWiz1)
_vehicledataset.ReadXml(New System.IO.StringReader(v1.Vehicle), XmlReadMode.ReadSchema)
v1.Dispose()
Else
'came from page 3
Dim v3 As VehicleWiz3 = DirectCast(context.Handler, VehicleWiz3)
_vehicledataset.ReadXml(New System.IO.StringReader(v3.Vehicle))
v3.Dispose()
End If
[/b]
Me.tbVehicleModel.Text = _vehicledataset.Tables(0).Rows(0).Item(13)
Me.tbVehicleYear.Text = _vehicledataset.Tables(0).Rows(0).Item(9)
Me.tbVIN.Text = _vehicledataset.Tables(0).Rows(0).Item(7)
Me.ddlVehicleColor.SelectedValue = _vehicledataset.Tables(0).Rows(0).Item(12)
Me.ddlVehicleMake.SelectedValue = _vehicledataset.Tables(0).Rows(0).Item(11)
Me.ddlVehicleStyle.SelectedValue = _vehicledataset.Tables(0).Rows(0).Item(10)
'add the dataset to this page's viewstate
'which is useful if we postback to the same page for some reason
[b] Dim sw As New System.IO.StringWriter
_vehicledataset.WriteXml(sw, XmlWriteMode.WriteSchema)
Me.ViewState.Add("vehicledata", sw.ToString)
[/b]
End If
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
[b]
'scrape data off page, store in dataset
getupdatedData()
'move to next page
Server.Transfer("VehicleWiz3.aspx")
[/b]
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
[b] 'scrape data off page, store in dataset
getupdatedData()
'move to previous page
Server.Transfer("VehicleWiz1.aspx")
[/b]End Sub
'this method gets the current data on the page, and puts it in the dataset
Private Sub getupdatedData()
Dim _vehicledataset As New DataSet
_vehicledataset.ReadXml(New System.IO.StringReader(Vehicle), XmlReadMode.ReadSchema)
With _vehicledataset.Tables(0).Rows(0)
.Item(13) = tbVehicleModel.Text
.Item(9) = tbVehicleYear.Text
.Item(7) = tbVIN.Text
.Item(12) = ddlVehicleColor.SelectedValue
.Item(11) = ddlVehicleMake.SelectedValue
.Item(10) = ddlVehicleStyle.SelectedValue
End With
Dim sw As New System.IO.StringWriter
_vehicledataset.WriteXml(sw, XmlWriteMode.WriteSchema)
Me.ViewState("vehicledata") = sw.ToString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'this responds to a cancel button, which closes the window
'in my case it was a popup wizard, so this made sense
Response.Redirect("../CLOSEME.ASPX")
End Sub
End Class
-
Apr 19th, 2004, 06:19 AM
#7
Thread Starter
Lively Member
Sorry but I am not still prepared to understand and to apply your code, so I will use my system. Anyway I will be been thankful to receive your opinion about my code.
To store the data filled in the form I use this subroutine:
(This is the second form page of three)
Code:
Sub userData(Sender As Object, e As EventArgs)
If (Page.IsValid) Then
Dim ds2 As DataSet
ds2 = CType(Session("UserData"), DataSet)
Dim row As DataRow
row = ds2.Tables(0).Rows(0)
row.Item("companyName") = name.Text
row.Item("State") = state.SelectedItem.Value
row.Item("city") = city.SelectedItem.Value
...
Session("UserData") = ds2
response.Redirect("Form3_NewUser.aspx")
End If
End Sub
Then to refill the fields with the user selections when the user decides come back to this second form page from the third page with a link.. :
Code:
Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim ds2 As DataSet
ds2 = CType(Session("UserData"), DataSet)
If Not isNothing(ds2.tables(0).rows(0)) then
name.Text() = ds2.Tables(0).rows(0).Item("companyName").ToString
state.SelectedItem.Value = ds2.Tables(0).rows(0).Item("State").ToString
city.SelectedItem.Value = ds2.Tables(0).rows(0).Item("city").ToString
...
End If
End If
End Sub
What do you think about this system of assigning a dataset to a session variable, and using a table to store the data? Is there an easy alternative of using a table to store the data? Because indeed I always only use one row, and it doesn’t seems a logical way of using a table...
Thank you
-
Apr 19th, 2004, 06:25 PM
#8
I wonder how many charact
You can certainly use a session variable. I always just stored a username, userguid, firstname and lastname of the session's user in session, and that was all I ever felt comfortable storing.
Now, you can certainly use session, just remember that whatever you store in there, stay alives through the current session, or until you explicity remove it, so anytime someone uses your app, it will use more and more server memory. For me, if my app had 1000+ users using it at one time, I'd be cautious. Again, I don't know what load you are expecting, so it might just be a tremendously mute point.
Anyway, you don't have to use a table, although it certainly is easy to write a dataset isn't it?
You could make a class and just be sure its properties serialize to strings when called to.
You could make a method SerializeMe() which returns an xml formatted string, which certainly makes it easy to store.
Or you may be able to get by on .Net's serializing abilities. You won't know until you test it, so good luck.
-
Apr 20th, 2004, 04:10 AM
#9
Thread Starter
Lively Member
Ok, thank you very much nemaroller !
I see that I have to consider seriously to learn to create a 'simple' struct or class in order to save server resources (my website will be basically to enter information and retrieve it), and I hope to have many users at the same time , despite the app would have a few users if one day starts to increase them it is better to have the application prepared and do not bother to user.
Too much data in the session variables and datasets consumes many server resources. Until now I have never created a class, I only have read two chapters of my manual about how to built an object or class. It seems very difficult… but I will try it.
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|