473,385 Members | 1,317 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,385 software developers and data experts.

asp code only works once in a while

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>

Jul 23 '05 #1
2 1078
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.

Jul 23 '05 #2
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!!

Jul 23 '05 #3

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

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
19
by: Vinod | last post by:
Hi, I have got a peculiar requirement. I want to distinquish between the color codes. I have got two text fields and i will enter the color codes there. The first text field will have ...
15
by: Enzo | last post by:
Hi Ng, It's possible to protect the source code of a js file? With PHP? Thanks in advance! Enzo
4
by: yanyo | last post by:
hi, im trying to figure out whats the problem with this program i get a runtime error but i dont see where the problem is i tried changing declaration but nothing if somrbody can try this on their...
0
by: jOs | last post by:
C#B - SHARED SOURCE PROJECT FOR A C# Browser Let's sort this stuff out once and for ALL. =============================================================== Anyone who's having problems in...
3
by: Russ | last post by:
I keep getting this message "The compiler failed with error code 2000" when pressing PF5 to run Debug. This is not a compile error, it gets past the compile. I get this when it tries to load up my...
1
by: rrstudio2 | last post by:
I was reading and modifying some VB code needed to import all of the excel files in a directory into one table in Access and ended up with the following which works. Public Sub...
0
by: firstquestion | last post by:
Hello, I need to pass a StringBuilder object to a custom unmanaged DLL. The code most of the time works great, however once in a while I get "Object reference not set to an instance of an object"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.