?
Solved

ASP - problem while "refresh" the screen

Posted on 2001-06-21
15
Medium Priority
?
310 Views
Last Modified: 2011-08-18
I am using the following samepage.asp to add name and age of a person to a database. When the "submit" is pressed the values are stored to the database after simple validation. If the user refresh the screen, again the same data is added into the database. How to restrict this?

=============samepage.asp===============
<% @Language="VBSCRIPT"%>
<%
 cName=request.querystring ("uname")
 if cName <> "" then
     ' get the values from the querystring
     ' add to database.
 end if
%>

<html>
<BODY>
<form name="f" action="samepage.asp" method="get">
<table>
<tr>
          <td>User Name</td>
          <td> <input type="text" name="uname"></td>
          <td>Age</td>
          <td> <input type="text" name="uage"></td>
</tr>
<tr>
     <td><input type="reset" value="Cancel"> </td>
     <td><input type="submit" name="SaveFile" value="Save" OnClick="return checking()" ></td>
</tr>
</table>
</form>
</body>
</html>
<script language="javascript">

function checking()
{

  if(document.f.uname.value=='' || document.f.uage.value=='')
  {
    alert("FAILURE: \nRequired fields are empty...! ");
     return false;
  }
return true;
}
</script>
==================end===============
help me.
0
Comment
Question by:arogyarajxavier
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +4
15 Comments
 
LVL 33

Expert Comment

by:hongjun
ID: 6216667
First of all you cannot restrict the Refresh dialog from appearing. However, you can do a simple trick on it.

I see that you are actually submitting to the same page. Try this to solve your problem.
<% @Language="VBSCRIPT"%>

<%
' Add this one
Response.Buffer = True
%>

<%
cName=request.querystring ("uname")
if cName <> "" then
    ' get the values from the querystring
    ' add to database.

    ' Add this one
    Response.Redirect "samepage.asp"
end if
%>

hongjun
0
 
LVL 2

Expert Comment

by:Fenatu
ID: 6216685
Use a seperate page for putting the stuff into the database. Then if you want, response.redirect back to the samepage.
0
 
LVL 33

Accepted Solution

by:
hongjun earned 80 total points
ID: 6216687
Another method is the submit the result to another page.
<form name="f" action="another_page.asp" method="get">
Then in another_page.asp, do this
<%
cName=request.querystring ("uname")
if cName <> "" then
    ' get the values from the querystring
    ' add to database.

    ' Add this one
end if
%>
<script language="JavaScript">
<!--
    window.document.location.replace("third_page.asp");
//-->
</script>


hongjun
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:arogyarajxavier
ID: 6216713
Its fine hongjun. but the problem is it wouldnot dispaly message like "Record is added", because after adding it loaded a fresh page immediately. so the user couldnot know whether the record is inserted or not. Thanks.
0
 
LVL 5

Expert Comment

by:nilapenn
ID: 6216920
You can very well give an alert in the javascript
<script language="JavaScript">
<!--
   alert("Record added sucessfully");
   window.document.location.replace("third_page.asp");
//-->
</script>


or you can pass a querystring to the third page and print the message in the thirdpage.

<script language="JavaScript">
<!--
  window.document.location.replace("third_page.asp?success=true");
//-->
</script>

then in thirdpage.asp

<%
if request.querystring("success")="true" then
Response.Write("Record Added Sucessfully")
end if
%>

0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 6216941
If you don't mind cookies, there's always setting a session variable on the data submit page.  At the the start of the page entry just check the value of the session variable...

If Session("entered") <> "T" Then
   <Submit Data>
   Session("entered") = "T"
Else
   <Error - Data Already Submitted>
End If
0
 

Author Comment

by:arogyarajxavier
ID: 6216974
leew, ur suggestion is good, but using this tech. we can insert record only once, if we need to add another then load the page again. thanks
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6216998
arogyarajxavier,

nilapeen comments is suit to you :)

Regards,
Wee Siong
0
 

Author Comment

by:arogyarajxavier
ID: 6217004
thanks weesiong, put the stuff in two separate pages is the solution right?
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6217122
arogyarajxavier,

yes, i more like nilapeen this comments, post with querystring

<script language="JavaScript">
<!--
 window.document.location.replace("third_page.asp?success=true");
//-->
</script>

then in thirdpage.asp

<%
if request.querystring("success")="true" then
Response.Write("Record Added Sucessfully")
end if
%>

actually if you want continue submit the data, it should be form.asp and non third_page.asp

The points for nilapeen :)

Regards,
Wee Siong
0
 
LVL 5

Expert Comment

by:raizon
ID: 6218475
This is what I do for situations like this.

1.  Before inserting data into the db I check to see if it already exists on something that I know will be unique like

strSQL = "SELECT * FROM table WHERE fname = '" & strFName & '" AND lname = '" & strLName & "' AND address = '" & strAddress & '"

set rst = conn.execute(strSQL)

If rst.EOF Then
  insert data
Else
  show that data already exists
End If

Either that or you can make your primary key be a group of fields such as a combination of fname, lname, and address.
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6218753
Ya. Definitely send to another page is a better choice as shown on my second method.

hongjun
0
 

Author Comment

by:arogyarajxavier
ID: 6226642
Thank you hongjun, for your timely respone. Thank you nilapenn and others who helped me a lot.
0
 

Author Comment

by:arogyarajxavier
ID: 6226654
thanks hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6231201
Glad that I can help here.

hongjun
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question