473,503 Members | 722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
nj********@hotmail.com
www.nathansokalski.com
Nov 18 '05 #1
4 1988
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.

Nov 18 '05 #2
"Nathan Sokalski" <nj********@hotmail.com> wrote in message news:<us**************@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.
Nov 18 '05 #3

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:us**************@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
nj********@hotmail.com
www.nathansokalski.com


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
Nov 18 '05 #4
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.


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2435
by: Nathan Sokalski | last post by:
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...
5
3290
by: Scott Tilton | last post by:
I am having a terrible time getting this to work. I am hoping someone out there can help me with very specific code examples. I am trying to get the linked tables in my Access 97 database to be...
2
2530
by: jdi | last post by:
Hello, I have a seemingly basic question about ASP.NET. I would like to create a page containing an image, which keeps swapping the url of the image source, without refreshing the entire page. ...
5
3472
by: Jensen Bredal | last post by:
Hello, I need to display self refreshing information on a web page written with asp.net. I would image that the info would be displayed either as part of a user control or a web control. How can...
2
2474
by: Ben | last post by:
Hi, One ASP.NET transactional page conducts a long transaction in a button click function. I want to display the transaction progress info in label control without refreshing page. It is...
5
1677
by: chimambo | last post by:
Hi all, I have a problem with maintaining data without refreshing manually in my system. I have a system which carries data across several pages. But if a user wants to go back to the previous...
13
7428
by: honey99 | last post by:
Hi! I have to fix a problem in JSP.Actually,i have a JSP page say Ex1.jsp.In this Ex1.jsp i have an anchor tag which links into another JSP page i.e when i click on the link another pop-up window...
1
1559
by: Steve S | last post by:
Hey guys, I'm stuck with using a GridBagSizer (wxPython) in a GUI Dialog and am having a frustrating time with refreshing it properly. Essentially, I've got to refresh the contents of the...
6
1938
by: shankari07 | last post by:
hi guys, I have a form in html which has the city drop down. when clicking the drop down a javascript is called and a file(test.txt) is created and the city is written into the file. Through php...
4
2534
by: thete | last post by:
how to avoid resubmitting the form in php
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.