Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a correction by going back on a two page form.

Status
Not open for further replies.

NuJoizey

MIS
Joined
Aug 16, 2006
Messages
450
Location
US
On the first page, users enter things into textboxes, then they click button_1 which does something like the paraphrased code below:

Code:
Protected Sub Button1_Click

        Call createPage1Array()
        dsAdd_NewAccount.Insert()
        Response.Redirect("page2")
End Sub

This captures the values entered by the user in a session variable so the app will remember the input values:

Code:
Sub createPage1Array()

        Dim page1Array(3) As String
        page1Array(0) = Me.Company.Text
        page1Array(1) = Me.Address1.Text
        page1Array(2) = Me.Address2.Text
       
        Session("page1Array") = page1Array

End Sub

The intent is to handle if the user submits to page2 and then suddenly realizes "oops, i messed up something on page1, let me go back"

On page2, there is a "GoBack" button whose btnGoBack_Click event is:

Code:
Response.Redirect("page1?GoBack=True")

and on page_load of page1, I have

Code:
If Request.QueryString("GoBack") = "True" Then
  Me.CompanyLegalName.Text = Session("page1Array")(0)
  Me.Address1.Text = Session("page1Array")(1)
  Me.Address2.Text = Session("page1Array")(2)
End If

which serves to re-populate the textboxes with the originally entered values.

PROBLEM: When the user makes a change to, say Address1.Text, and then clicks on Button1_Click to re-submit the new value of Address1.Text is not passed. It's the old value. What I want is to pass the new value.

I'm sure this is by design, but I don't know how to get it to do what I need it to do. I can't seem to figure out whether I have my events mixed up, or whether it's something to do with post/postback method, or session variables, or what???

I am aware that the mult-view control is supposed to handle this situation more elegantly, but I am trying to work with an existing design without wasting time doing a full page redesign on something that will be scrapped soon anyway.

 
Have you ran this code in Debug mode and followed through the Button1_Click event on your Page1 through your entire testing process? That is where I would suggest to start. There isn't enough info (code) here for me to test your problem on my end.
 
multiview wouldn't solve this problem elegantly because views of a multiview are mutually exclusive and no nothing about each other. If you were to rework the form you would want to use a Wizard control.

if you're checking for session without also checking for postback then your values will be overwritten. by session.
the logic should look something like this

Code:
override OnLoad(EventArgs e)
{
   if(!IsPostBack)
   {
       //bind drop downs and things like that
       Array array = Session("Array") as Array;
       if(array != null)
       {
           //set control values.
       }
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
thanks for the response guys. I did run it in debug mode, but it didn't immediately jump out at me. Turns out it was something elementary, as I find many of my postings are.

arrrgh! The problem was simply that I had my events mixed up, which was one of the problems I thought it could be initally.

For it to work as desired, this code needed to be put in Page_Init, NOT Page_Load:
Code:
If Request.QueryString("GoBack") = "True" Then
  Me.CompanyLegalName.Text = Session("page1Array")(0)
  Me.Address1.Text = Session("page1Array")(1)
  Me.Address2.Text = Session("page1Array")(2)
End If

And yes, as jmeckley said, my values kept getting overwritten.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top