Go back w/o loading the form?

Discussion in 'ASP General' started by Rolf Rosenquist, Feb 13, 2007.

  1. From a page with a form I collect the fields in the next page. The fields
    are compared with a database and if a certain condition does not fit, I want
    to go back to the first page with the form, and still keep all the other
    fields as they were written.

    If I use Response.Redirect the form will be loaded empty again. The same if
    I use a button on page 2 with onClick="history.Back". Isn't there a way to
    go back and keep the already written fields in the form on the first page,
    as if the user just had hit the Back icon in IE?

    / Rolf
     
    Rolf Rosenquist, Feb 13, 2007
    #1
    1. Advertising

  2. Rolf Rosenquist

    Mike Brind Guest

    "Rolf Rosenquist" <> wrote in message
    news:...
    > From a page with a form I collect the fields in the next page. The fields
    > are compared with a database and if a certain condition does not fit, I
    > want
    > to go back to the first page with the form, and still keep all the other
    > fields as they were written.
    >
    > If I use Response.Redirect the form will be loaded empty again. The same
    > if
    > I use a button on page 2 with onClick="history.Back". Isn't there a way to
    > go back and keep the already written fields in the form on the first page,
    > as if the user just had hit the Back icon in IE?
    >


    There are a number of ways to do this. Here's one that will cope with the
    fact that one page posts to another.

    ExampleForm.asp

    <form method="post" action="Action.asp">
    <p>Enter First name: <input type="text" name="FirstName"
    value="<%=Session("FirstName")%>"></p>
    <p>Enter Second name: <input type="text" name="SecondName"
    value="<%=Session("SecondName")%>"></p>
    <p><input type="submit" name="submit" value="Click Me"></p>

    Action.asp

    <%
    Dim x, boolValid

    For Each x in Request.Form
    Session(x) = Request.Form(x)
    Next

    boolValid = True
    'Validate form values
    If 'any test fails Then
    boolValid=false
    End If
    If boolValid = false Then Response.Redirect("ExampleForm.asp")
    %>

    --
    Mike Brind
     
    Mike Brind, Feb 13, 2007
    #2
    1. Advertising

  3. Mike, do you mean that I should then repopulate the form from the Session(x)
    if I come back to the first page?
    Isn't it too much waste of server memory to use session variables for normal
    data between pages?

    If someone uses the back button in the browser, all the fields are still
    there. Couldn't I do the same thing with asp code?

    / Rolf



    "Mike Brind" <> skrev i meddelandet
    news:...
    >
    > "Rolf Rosenquist" <> wrote in message
    > news:...
    > > From a page with a form I collect the fields in the next page. The

    fields
    > > are compared with a database and if a certain condition does not fit, I
    > > want
    > > to go back to the first page with the form, and still keep all the other
    > > fields as they were written.
    > >
    > > If I use Response.Redirect the form will be loaded empty again. The same
    > > if
    > > I use a button on page 2 with onClick="history.Back". Isn't there a way

    to
    > > go back and keep the already written fields in the form on the first

    page,
    > > as if the user just had hit the Back icon in IE?
    > >

    >
    > There are a number of ways to do this. Here's one that will cope with the
    > fact that one page posts to another.
    >
    > ExampleForm.asp
    >
    > <form method="post" action="Action.asp">
    > <p>Enter First name: <input type="text" name="FirstName"
    > value="<%=Session("FirstName")%>"></p>
    > <p>Enter Second name: <input type="text" name="SecondName"
    > value="<%=Session("SecondName")%>"></p>
    > <p><input type="submit" name="submit" value="Click Me"></p>
    >
    > Action.asp
    >
    > <%
    > Dim x, boolValid
    >
    > For Each x in Request.Form
    > Session(x) = Request.Form(x)
    > Next
    >
    > boolValid = True
    > 'Validate form values
    > If 'any test fails Then
    > boolValid=false
    > End If
    > If boolValid = false Then Response.Redirect("ExampleForm.asp")
    > %>
    >
    > --
    > Mike Brind
    >
    >
     
    Rolf Rosenquist, Feb 13, 2007
    #3
  4. Rolf Rosenquist

    Mike Brind Guest

    You can't rely on the back button maintaining form state. The back button
    belongs to the browser, and as such is outside of the control of an asp
    developer.

    Personally, I get pages to post to themselves in the vast majority of cases.
    I usually do this kind of thing:

    <%
    Sub ShowForm
    %>
    <form method="post" action="">
    <p>Enter First name: <input type="text" name="FirstName"
    value="<%=Request.form("FirstName")%>"></p>
    <p>Enter Second name: <input type="text" name="SecondName"
    value="<%=Request.Fom("SecondName")%>"></p>
    <p><input type="submit" name="submit" value="Click Me"></p>
    <%
    End Sub

    If Not IsEmpty(Request.Form("submit")) Then
    'Form posted
    'validate values
    'if validation fails, show form
    Call ShowForm
    Else
    Success
    Else
    Call ShowForm
    End If
    %>

    But of course, some forms need more than one page. If you think that using
    session variables will be too much for your environment, you can use a
    database, text files, hidden fields etc.

    --
    Mike Brind

    --
    Mike Brind







    "Rolf Rosenquist" <> wrote in message
    news:u6h1n%...
    > Mike, do you mean that I should then repopulate the form from the
    > Session(x)
    > if I come back to the first page?
    > Isn't it too much waste of server memory to use session variables for
    > normal
    > data between pages?
    >
    > If someone uses the back button in the browser, all the fields are still
    > there. Couldn't I do the same thing with asp code?
    >
    > / Rolf
    >
    >
    >
    > "Mike Brind" <> skrev i meddelandet
    > news:...
    >>
    >> "Rolf Rosenquist" <> wrote in message
    >> news:...
    >> > From a page with a form I collect the fields in the next page. The

    > fields
    >> > are compared with a database and if a certain condition does not fit, I
    >> > want
    >> > to go back to the first page with the form, and still keep all the
    >> > other
    >> > fields as they were written.
    >> >
    >> > If I use Response.Redirect the form will be loaded empty again. The
    >> > same
    >> > if
    >> > I use a button on page 2 with onClick="history.Back". Isn't there a way

    > to
    >> > go back and keep the already written fields in the form on the first

    > page,
    >> > as if the user just had hit the Back icon in IE?
    >> >

    >>
    >> There are a number of ways to do this. Here's one that will cope with
    >> the
    >> fact that one page posts to another.
    >>
    >> ExampleForm.asp
    >>
    >> <form method="post" action="Action.asp">
    >> <p>Enter First name: <input type="text" name="FirstName"
    >> value="<%=Session("FirstName")%>"></p>
    >> <p>Enter Second name: <input type="text" name="SecondName"
    >> value="<%=Session("SecondName")%>"></p>
    >> <p><input type="submit" name="submit" value="Click Me"></p>
    >>
    >> Action.asp
    >>
    >> <%
    >> Dim x, boolValid
    >>
    >> For Each x in Request.Form
    >> Session(x) = Request.Form(x)
    >> Next
    >>
    >> boolValid = True
    >> 'Validate form values
    >> If 'any test fails Then
    >> boolValid=false
    >> End If
    >> If boolValid = false Then Response.Redirect("ExampleForm.asp")
    >> %>
    >>
    >> --
    >> Mike Brind
    >>
    >>

    >
    >
     
    Mike Brind, Feb 14, 2007
    #4
  5. Yes it works now with hidden fields, but I have found it is necessary to use
    a submit button to get them back to page1. They do not appear, when I try to
    do it in the background with Response.Redirect "page1,asp"

    Is there a way to catch the hidden fields without a button?
    / Rolf




    "Mike Brind" <> skrev i meddelandet
    news:%...
    > You can't rely on the back button maintaining form state. The back button
    > belongs to the browser, and as such is outside of the control of an asp
    > developer.
    >
    > Personally, I get pages to post to themselves in the vast majority of

    cases.
    > I usually do this kind of thing:
    >
    > <%
    > Sub ShowForm
    > %>
    > <form method="post" action="">
    > <p>Enter First name: <input type="text" name="FirstName"
    > value="<%=Request.form("FirstName")%>"></p>
    > <p>Enter Second name: <input type="text" name="SecondName"
    > value="<%=Request.Fom("SecondName")%>"></p>
    > <p><input type="submit" name="submit" value="Click Me"></p>
    > <%
    > End Sub
    >
    > If Not IsEmpty(Request.Form("submit")) Then
    > 'Form posted
    > 'validate values
    > 'if validation fails, show form
    > Call ShowForm
    > Else
    > Success
    > Else
    > Call ShowForm
    > End If
    > %>
    >
    > But of course, some forms need more than one page. If you think that

    using
    > session variables will be too much for your environment, you can use a
    > database, text files, hidden fields etc.
    >
    > --
    > Mike Brind
    >
    > --
    > Mike Brind
    >
    >
    >
    >
    >
    >
    >
    > "Rolf Rosenquist" <> wrote in message
    > news:u6h1n%...
    > > Mike, do you mean that I should then repopulate the form from the
    > > Session(x)
    > > if I come back to the first page?
    > > Isn't it too much waste of server memory to use session variables for
    > > normal
    > > data between pages?
    > >
    > > If someone uses the back button in the browser, all the fields are still
    > > there. Couldn't I do the same thing with asp code?
    > >
    > > / Rolf
    > >
    > >
    > >
    > > "Mike Brind" <> skrev i meddelandet
    > > news:...
    > >>
    > >> "Rolf Rosenquist" <> wrote in message
    > >> news:...
    > >> > From a page with a form I collect the fields in the next page. The

    > > fields
    > >> > are compared with a database and if a certain condition does not fit,

    I
    > >> > want
    > >> > to go back to the first page with the form, and still keep all the
    > >> > other
    > >> > fields as they were written.
    > >> >
    > >> > If I use Response.Redirect the form will be loaded empty again. The
    > >> > same
    > >> > if
    > >> > I use a button on page 2 with onClick="history.Back". Isn't there a

    way
    > > to
    > >> > go back and keep the already written fields in the form on the first

    > > page,
    > >> > as if the user just had hit the Back icon in IE?
    > >> >
    > >>
    > >> There are a number of ways to do this. Here's one that will cope with
    > >> the
    > >> fact that one page posts to another.
    > >>
    > >> ExampleForm.asp
    > >>
    > >> <form method="post" action="Action.asp">
    > >> <p>Enter First name: <input type="text" name="FirstName"
    > >> value="<%=Session("FirstName")%>"></p>
    > >> <p>Enter Second name: <input type="text" name="SecondName"
    > >> value="<%=Session("SecondName")%>"></p>
    > >> <p><input type="submit" name="submit" value="Click Me"></p>
    > >>
    > >> Action.asp
    > >>
    > >> <%
    > >> Dim x, boolValid
    > >>
    > >> For Each x in Request.Form
    > >> Session(x) = Request.Form(x)
    > >> Next
    > >>
    > >> boolValid = True
    > >> 'Validate form values
    > >> If 'any test fails Then
    > >> boolValid=false
    > >> End If
    > >> If boolValid = false Then Response.Redirect("ExampleForm.asp")
    > >> %>
    > >>
    > >> --
    > >> Mike Brind
    > >>
    > >>

    > >
    > >

    >
    >
     
    Rolf Rosenquist, Feb 15, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joby
    Replies:
    0
    Views:
    1,637
  2. sylvia sil
    Replies:
    1
    Views:
    619
    Curt_C [MVP]
    Dec 29, 2004
  3. =?Utf-8?B?Z29yaWxsYQ==?=
    Replies:
    1
    Views:
    774
    Masudur
    May 25, 2007
  4. matthias s
    Replies:
    0
    Views:
    166
    matthias s
    Sep 20, 2007
  5. VbUser25
    Replies:
    1
    Views:
    116
    Steven Burn
    Dec 21, 2004
Loading...

Share This Page