Refreshing without resubmitting

Ask a Question related to ASP Components, Design and Development.

  1. #1

    Default Refreshing without resubmitting

    When form data is submitted to an ASP page using the POST method, it is not
    visible in the URL, but it is still resubmitted if the user clicks the
    Refresh button. This can cause statistical data to be accidentally submitted
    multiple times, making the results incorrect. I would like like the user to
    be able to click the Refresh button without resubmitting the form data. Is
    there some way to "erase" the form data after it is used so that the Refresh
    button does not resubmit it? Any help would be appreciated. Thanks.
    --
    Nathan Sokalski
    [email]njsokalski@hotmail.com[/email]
    [url]www.nathansokalski.com[/url]


    Nathan Sokalski Guest

  2. Similar Questions and Discussions

    1. Refreshing datagrid
      Hi all... I have an asp page with a datagrid, and a imagebutton to add a new row. every time I click that new button, a new page appear and user...
    2. Refreshing, lineto's...
      I have a line, that is being drawn, between two movieclips, with this code Ax = _root.A._x Ay = _root.A._y Bx = _root.B._x By = _root.B._y...
    3. content not refreshing
      I've been doing asp for years but this one stumps me. My pages are not refreshing content. Sometimes they refresh after a minute or two. I've...
    4. [PHP] Refreshing After Submitting a From
      > Does anyone have any ideas on how I could do this? Is there any reason you can't throw a refresh command into a header before any data is sent?...
    5. refreshing a checkbox
      I posted this in a google google group and havent had any luck as of yet. Maybe you guys can help me. I have a list box that gets it data from a...
  3. #2

    Default Re: Refreshing without resubmitting

    Hi Nathan

    I don't know whether this is the simplest solution but it should work.
    Submit a time stamp with your data that you serve with the form in a
    hidden field. Store the time stamp with the first submission, perhaps in
    the cache with a shortish life time, and then don't act on subsequently
    submitted data if the time stamp is the present in your chosen store.
    Maybe you could derive a class from the Page class that encapsulates
    that functionality and use it as the base for all of your pages to
    prevent this behaviour.

    Hope this helps


    Graham

    Nathan Sokalski wrote:
    > When form data is submitted to an ASP page using the POST method, it is not
    > visible in the URL, but it is still resubmitted if the user clicks the
    > Refresh button. This can cause statistical data to be accidentally submitted
    > multiple times, making the results incorrect. I would like like the user to
    > be able to click the Refresh button without resubmitting the form data. Is
    > there some way to "erase" the form data after it is used so that the Refresh
    > button does not resubmit it? Any help would be appreciated. Thanks.
    Graham Pengelly Guest

  4. #3

    Default Re: Refreshing without resubmitting

    "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message news:<usxe82mXEHA.3596@tk2msftngp13.phx.gbl>...
    > When form data is submitted to an ASP page using the POST method, it is not
    > visible in the URL, but it is still resubmitted if the user clicks the
    > Refresh button. This can cause statistical data to be accidentally submitted
    > multiple times, making the results incorrect. I would like like the user to
    > be able to click the Refresh button without resubmitting the form data. Is
    > there some way to "erase" the form data after it is used so that the Refresh
    > button does not resubmit it? Any help would be appreciated. Thanks.
    One workaround is to have the page which accept the form submission do
    it's processing, then redirect to the page which displays the data.
    The page which displays the data should not have any form data
    submitted to it, nor does it process any data.
    Larry Bud Guest

  5. #4

    Default Re: Refreshing without resubmitting


    "Nathan Sokalski" <njsokalski@hotmail.com> wrote in message
    news:usxe82mXEHA.3596@tk2msftngp13.phx.gbl...
    > When form data is submitted to an ASP page using the POST method, it is
    not
    > visible in the URL, but it is still resubmitted if the user clicks the
    > Refresh button. This can cause statistical data to be accidentally
    submitted
    > multiple times, making the results incorrect. I would like like the user
    to
    > be able to click the Refresh button without resubmitting the form data. Is
    > there some way to "erase" the form data after it is used so that the
    Refresh
    > button does not resubmit it? Any help would be appreciated. Thanks.
    > --
    > Nathan Sokalski
    > [email]njsokalski@hotmail.com[/email]
    > [url]www.nathansokalski.com[/url]
    >
    >
    Nathan --

    Not knowing exactly how your code is written, I can only give you some
    generic suggestions.

    * In the server-side script, you can check
    request.servervariables("REQUEST_METHOD") to determine if it's a POST. If
    so, execute the processing to perform the computations, otherwise, only send
    the results. Example:

    select case lcase(request.servervariables("REQUEST_METHOD"))
    case "post"
    IsPostback = True 'a boolean to keep track of whether it's post
    or get
    ' pull the inputs from the form and do the calculations
    ' ....
    ' store the results in a session variable or database you can
    send down
    case "get"
    IsPostback = False
    ' retrieve the saved results and send them down
    case else
    ' probably a spider crawling so deal with dismissing it
    end select

    * If you use the preceding approach, you may want to beef it up some by
    adding a test in the case "post" to make sure your submit button was used to
    submit perform the submit.

    * Depending on the size and nature of the results, you can store them to a
    scripting.dictionary object (for simple label-value pairs) and stash it in
    the session object, or a database or xml file and stash the retrieval string
    in the session. Use a separate function you can call from the page
    generation code or in the <body> to return the container and generate the
    output HTML as you traverse it, or return fully formatted HTML.

    <% option explicit %>
    <%
    response.buffer = true
    dim IsPostback, nAmt, nIntRate, nYears
    IsPostback = False
    nAmt = 0
    nIntRate = 0
    nYears = 0
    with request
    if lcase(.servervariables("REQUEST_METHOD")) = "post" then
    IsPostback = True
    nAmt = clng(.form("Amount"))
    nIntRate = clng(.form("Interest"))
    nYears = clng(.form("Years"))
    If CalcResults(nAmt, nIntRate, nYears) Then
    ' deal with everything OK
    Else
    ' deal with error
    End If
    end if
    end with

    Function CalcResults(byval Amount, byval IntRate, byval Years)
    dim blnRetVal, cn, strSQL, i, PmtAmt
    blnRetVal = True
    ' check that the numbers are reasonable
    ' if not, blnRetVal = False and Exit Function

    ' open database connection
    set cn = createobject("ADODB.Connection")
    cn.open 'yaddayadda
    strSQL = "INSERT INTO results_table " & _
    " (whos_asking, field1, field2) VALUES ("
    for i = 1 to Years
    ' compute the loan payment for each year
    PmtAmt = ...
    ' save the results
    cn.execute strSQL & session("ThisUserID") & _
    ", " & i & ", " & PmtAmt & ")"
    ' error trapping would set blnRetVal = False
    next
    cn.close
    set cn = nothing
    CalcResults = blnRetVal
    End Function

    Sub RenderOutputAsTable
    ' example: write a recordset to an HTML table
    ' assumes nothing will go wrong, always have error handling
    dim cn, strSQL, rsResults
    strSQL = "SELECT field1, field2 FROM results_table " & _
    " WHERE whos_asking = " & session("ThisUserID")
    set cn = createobject("ADODB.Connection")
    ' prep and open the connection
    cn.open 'yaddayadda
    with rsResults
    .cursortype = adOpenStatic
    .locktype = adOpenForwardOnly
    .activeconnection = cn
    .open strSQL
    .activeconnection = nothing
    cn.close
    set cn = nothing
    response.write "<table><tr><td>Field_1</td>" & _
    "<td>Field_2</td></tr>"
    do until .EOF
    response.write "<tr><td>" & .fields(0) & "</td>" & _
    "<td>" & .fields(1) & "</td></tr>" & vbCrLf
    .movenext
    loop
    response.write "</table>" & vbCrLf
    .close
    end with
    set rsResult = nothing
    End Sub
    %>
    <html>
    <body>
    <p>surrounding html</p>
    <form name="MyForm" method="POST">
    Amount: <input type="text" name="Amount" value="<%=nAmt%>">
    Int.%: <input type="text" name="Interest" value="<%=nIntRate%>">
    Years: <input type="text" name="Years" value="<%=nYears%>">
    <% if IsPostback then %>
    <p>Results for <%=session("ThisUserID")%><br>
    (<%=nAmt%> for <%=nYears%> at <%=nIntRate%>%)</p>
    <% RenderOutputAsTable %>
    <p align="center">
    <input type="submit" name="SubmitButton" value="Submit">
    </p>
    </form>
    </body>
    </html>

    This is very over-simplified, but should give you an idea of how it would
    work.

    Mind you, this solution only works for classic ASP. You would have to use a
    different strategy for ASP.NET as you can't intermix script and HTML. It
    would be somewhat similar as ASP.NET has the postback check built-in, but
    all your assignments would be server-side, and you have to be cognizant of
    interaction with viewstate. There are some good articles on fiddling with
    viewstate up on MSDN that can give some more guidance.

    Alan


    J. Alan Rueckgauer Guest

  6. #5

    Default Re: Refreshing without resubmitting

    AAARRRRGGGGHHHHHHHHHHH!!!!! You posted in multiple newsgroups!!!!!!!
    (Picking myself up from the floor)

    I'll be posting a reply just to microsoft.public.inetserver.asp.general


    Graham Pengelly wrote:
    > Hi Nathan
    >
    > I don't know whether this is the simplest solution but it should work.
    > Submit a time stamp with your data that you serve with the form in a
    > hidden field. Store the time stamp with the first submission, perhaps in
    > the cache with a shortish life time, and then don't act on subsequently
    > submitted data if the time stamp is the present in your chosen store.
    > Maybe you could derive a class from the Page class that encapsulates
    > that functionality and use it as the base for all of your pages to
    > prevent this behaviour.
    >
    > Hope this helps
    >
    >
    > Graham
    >
    > Nathan Sokalski wrote:
    >
    >> When form data is submitted to an ASP page using the POST method, it
    >> is not
    >> visible in the URL, but it is still resubmitted if the user clicks the
    >> Refresh button. This can cause statistical data to be accidentally
    >> submitted
    >> multiple times, making the results incorrect. I would like like the
    >> user to
    >> be able to click the Refresh button without resubmitting the form
    >> data. Is
    >> there some way to "erase" the form data after it is used so that the
    >> Refresh
    >> button does not resubmit it? Any help would be appreciated. Thanks.
    David C. Holley Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139