asp code only works once in a while

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Isabel

    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.dt d">
    <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("FirstN ame")<>"" then
    set conn = server.createob ject("adodb.con nection")
    conn.open("Prov ider=Microsoft. Jet.OLEDB.4.0;d ata source=" &
    server.MapPath( "target\Target1 .mdb"))
    SQLStmt = "SELECT count(*) as rv FROM tblPerson WHERE FirstName='" &
    Request("FirstN ame") & "';"
    vRecNo = ""
    Set oRS = conn.execute(SQ LStmt)
    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("FirstN ame") & "');"
    conn.execute(SQ LStmt)
    SQLStmt = "SELECT RecNo FROM tblPerson WHERE FirstName='" &
    Request("FirstN ame") & "';"
    Set oRS = conn.execute(SQ LStmt)
    SQLStmt = ""
    vRecNo = oRS("RecNo")
    Session("aRecNo ") = vRecNo
    oRS.Close
    Set oRS = Nothing
    end if
    end if
    end sub
    %>

    <%
    Response.CacheC ontrol = "no-cache"
    Response.AddHea der "Pragma", "no-cache"
    Response.Expire s = 0

    if Session("aRecNo ") <> "" then
    set conn = server.createob ject("adodb.con nection")
    conn.open("Prov ider=Microsoft. Jet.OLEDB.4.0;d ata source=" &
    server.MapPath( "target\Target1 .mdb"))
    SQLStmt = "SELECT * FROM tblPerson WHERE RecNo=" & Session("aRecNo ")
    Set oRS = conn.execute(SQ LStmt)
    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.a sp" >
    <input name="Submit" type="submit" value="Submit"
    onclick="locati on.reload();" />
    <textarea name="FirstName "><%=vFirstName %></textarea>
    </form>

    </body>
    </html>

  • Lee

    #2
    Re: asp code only works once in a while

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

    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.

    Comment

    • Isabel

      #3
      Re: asp code only works once in a while

      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("f irstname") was populated!

      Thank you once again!!

      Comment

      Working...