473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Jul 19 '05 #1
4 2429
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.

Jul 19 '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.
Jul 19 '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
Jul 19 '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.


Jul 19 '05 #5

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

Similar topics

5
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
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. ...
4
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
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
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
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
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...
6
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
by: thete | last post by:
how to avoid resubmitting the form in php
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...

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.