Go back w/o loading the form?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rolf Rosenquist

    Go back w/o loading the form?

    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.Redire ct the form will be loaded empty again. The same if
    I use a button on page 2 with onClick="histor y.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


  • Mike Brind

    #2
    Re: Go back w/o loading the form?


    "Rolf Rosenquist" <rolf@nomail.co mwrote in message
    news:ObxMbR2THH A.996@TK2MSFTNG P02.phx.gbl...
    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.Redire ct the form will be loaded empty again. The same
    if
    I use a button on page 2 with onClick="histor y.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="<%=Sessi on("FirstName") %>"></p>
    <p>Enter Second name: <input type="text" name="SecondNam e"
    value="<%=Sessi on("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.Redire ct("ExampleForm .asp")
    %>

    --
    Mike Brind


    Comment

    • Rolf Rosenquist

      #3
      Re: Go back w/o loading the form?

      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" <paxtonend@hotm ail.comskrev i meddelandet
      news:OiORSy6THH A.868@TK2MSFTNG P05.phx.gbl...
      >
      "Rolf Rosenquist" <rolf@nomail.co mwrote in message
      news:ObxMbR2THH A.996@TK2MSFTNG P02.phx.gbl...
      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.Redire ct the form will be loaded empty again. The same
      if
      I use a button on page 2 with onClick="histor y.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="<%=Sessi on("FirstName") %>"></p>
      <p>Enter Second name: <input type="text" name="SecondNam e"
      value="<%=Sessi on("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.Redire ct("ExampleForm .asp")
      %>
      >
      --
      Mike Brind
      >
      >

      Comment

      • Mike Brind

        #4
        Re: Go back w/o loading the form?

        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="<%=Reque st.form("FirstN ame")%>"></p>
        <p>Enter Second name: <input type="text" name="SecondNam e"
        value="<%=Reque st.Fom("SecondN ame")%>"></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" <rolf@nomail.co mwrote in message
        news:u6h1n%236T HHA.1016@TK2MSF TNGP04.phx.gbl. ..
        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" <paxtonend@hotm ail.comskrev i meddelandet
        news:OiORSy6THH A.868@TK2MSFTNG P05.phx.gbl...
        >>
        >"Rolf Rosenquist" <rolf@nomail.co mwrote in message
        >news:ObxMbR2TH HA.996@TK2MSFTN GP02.phx.gbl...
        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.Redire ct the form will be loaded empty again. The
        same
        if
        I use a button on page 2 with onClick="histor y.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.as p
        >>
        ><form method="post" action="Action. asp">
        ><p>Enter First name: <input type="text" name="FirstName "
        >value="<%=Sess ion("FirstName" )%>"></p>
        ><p>Enter Second name: <input type="text" name="SecondNam e"
        >value="<%=Sess ion("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.Redire ct("ExampleForm .asp")
        >%>
        >>
        >--
        >Mike Brind
        >>
        >>
        >
        >

        Comment

        • Rolf Rosenquist

          #5
          Re: Go back w/o loading the form?

          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.Redire ct "page1,asp"

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




          "Mike Brind" <dummy@newsgrou ps.comskrev i meddelandet
          news:%23heEx8AU HHA.5100@TK2MSF TNGP06.phx.gbl. ..
          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="<%=Reque st.form("FirstN ame")%>"></p>
          <p>Enter Second name: <input type="text" name="SecondNam e"
          value="<%=Reque st.Fom("SecondN ame")%>"></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" <rolf@nomail.co mwrote in message
          news:u6h1n%236T HHA.1016@TK2MSF TNGP04.phx.gbl. ..
          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" <paxtonend@hotm ail.comskrev i meddelandet
          news:OiORSy6THH A.868@TK2MSFTNG P05.phx.gbl...
          >
          "Rolf Rosenquist" <rolf@nomail.co mwrote in message
          news:ObxMbR2THH A.996@TK2MSFTNG P02.phx.gbl...
          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.Redire ct the form will be loaded empty again. The
          same
          if
          I use a button on page 2 with onClick="histor y.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="<%=Sessi on("FirstName") %>"></p>
          <p>Enter Second name: <input type="text" name="SecondNam e"
          value="<%=Sessi on("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.Redire ct("ExampleForm .asp")
          %>
          >
          --
          Mike Brind
          >
          >
          >
          >

          Comment

          Working...