asp code only works once in a while

I

Isabel

hi everyone,
I have an annoying problem of with asp.
Right now, when i type in data in textbox and hit submit, the text
entered stays displayed in the textbox, however if I type in new data,
it will not stay but revert to what was previously written in. BUT if I
keep trying (by typing in new data and hitting submit) eventually one
of the attempts will work (1 out of 20 tries the new data will remain
in the textbox, all other attempts it reverts to what was there prior)
Does anyone know what is wrong? I thought something was being cached
but i've added all the code i can think of to keep it from caching.
thanks if anyone knows!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />
</head>
<%
sub SaveData()
if Request("FirstName")<>"" then
set conn = server.createobject("adodb.connection")
conn.open("Provider=Microsoft.Jet.OLEDB.4.0;data source=" &
server.MapPath("target\Target1.mdb"))
SQLStmt = "SELECT count(*) as rv FROM tblPerson WHERE FirstName='" &
Request("FirstName") & "';"
vRecNo = ""
Set oRS = conn.execute(SQLStmt)
if oRS("RV")<>0 then
oRS.Close
Set oRS = Nothing
else
oRS.Close
Set oRS = Nothing
SQLStmt = " INSERT INTO tblPerson ("
SQLStmt = SQLStmt & "FirstName)"
SQLStmt = SQLStmt & "VALUES ('"
SQLStmt = SQLStmt & Request("FirstName") & "');"
conn.execute(SQLStmt)
SQLStmt = "SELECT RecNo FROM tblPerson WHERE FirstName='" &
Request("FirstName") & "';"
Set oRS = conn.execute(SQLStmt)
SQLStmt = ""
vRecNo = oRS("RecNo")
Session("aRecNo") = vRecNo
oRS.Close
Set oRS = Nothing
end if
end if
end sub
%>

<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = 0

if Session("aRecNo") <> "" then
set conn = server.createobject("adodb.connection")
conn.open("Provider=Microsoft.Jet.OLEDB.4.0;data source=" &
server.MapPath("target\Target1.mdb"))
SQLStmt = "SELECT * FROM tblPerson WHERE RecNo=" & Session("aRecNo")
Set oRS = conn.execute(SQLStmt)
if not oRS.eof then
vFirstName = oRS("FirstName")
end if
oRS.Close
Set oRS = Nothing
end if
%>
<body>
<form name="form1" method="post" onsubmit="<% call SaveData()%>"
Action="test1.asp" >
<input name="Submit" type="submit" value="Submit"
onclick="location.reload();" />
<textarea name="FirstName"><%=vFirstName%></textarea>
</form>

</body>
</html>
 
L

Lee

Isabel said:
hi everyone,
I have an annoying problem of with asp.
<body>
<form name="form1" method="post" onsubmit="<% call SaveData()%>"
Action="test1.asp" >
<input name="Submit" type="submit" value="Submit"
onclick="location.reload();" />

I was about to redirect you to an ASP group, but I see that your problem does
happen to involve the only bit of Javascript code in the page.

You are telling the browser to reload the page at the same time that you're
telling it to submit the page. Expect unexpected results.

Onclick handlers on Submit buttons are almost always a bad idea, and this one is
particularly bad. Get rid of that onclick attribute. The browser knows what to
do when you click a Submit button.
 
I

Isabel

wow!! u fixed it! I can't believe it! thank you thank thank you!
I worked all Christmas vacation on this!
I took out the onclick and then put the savedata function to run only
when request.form("firstname") was populated!

Thank you once again!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top