how to check for page refresh and page submit?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gotonagle
    New Member
    • Nov 2007
    • 19

    how to check for page refresh and page submit?

    hi,
    can some help me in this regard
    i m entering some values in my databse from my asp page. for this i m using a submit button which submit the form to a new page that is 'insert.asp'. this page perform insertion and redirect it back to my previos page.
    can i not do this insertion on the same page?
    if i wirte insertin code on the same page it perform insertion for the page refresh also...thats why i m using another page(some people says why user refresh page?..but we can not restrick the user to not to refresh page...)....
    so is there any way when i can perform insertion on submit click only and not on page refresh...
    or is there any way to do call two different server side function(or perform two different code) on two different buttons.

    pls help....
    thnx in advance..

    Rahul
  • JamieHowarth0
    Recognized Expert Contributor
    • May 2007
    • 537

    #2
    Hi Rahul,

    So if I've evaluated what you've asked for correctly, you are entering values into a form, then sending these to the page "insert.asp " and once inserted, you are redirecting the user back to the input page (for the purposes of example, "input.asp" )?

    If you can provide your sample code for "input.asp" and "insert.asp " then I can walk you through it and show you how to submit the data to the same ASP page, process it and do the redirect, all in a single page.

    If you can't provide your sample code then I can only advise you - use a hidden input in your form in "input.asp" and submit the data to "input.asp" - you can then check whether the user has refreshed using some simple error- and value-checking, and then load up input.asp again.

    Best regards,

    medicineworker

    Comment

    • gotonagle
      New Member
      • Nov 2007
      • 19

      #3
      hi
      thnx for ur interesr in prob

      it was my insert .asp


      <html>
      <head>
      <title>Dispal y on same page</title>
      </head>
      <body >
      <form>

      </form>

      <%

      set Conn = server.createob ject("adodb.con nection")
      Conn.Open "driver={sq l server}; server=SERVERNA ME; database=DATABA SE; uid=UID; pwd=PASSWORD;"

      sql="INSERT TABLE info VALUES"
      sql=sql & "( '" & Request.Form("N ame") & "',"
      sql=sql & "'" & Request.Form("d ob") & "',"
      sql=sql & "'" & Request.Form("g ender") & "',"
      sql=sql & "'" & Request.Form("d egree") & "',"
      sql=sql & "'" & Request.Form("a ddress") & "')"


      conn.Execute sql,recAffected
      Response.write( "inserted!!!!!! !!!!!!!!!")
      conn.close
      Response.redire ct("ASPAssignme nt2.asp")

      %>


      </body>
      </html>

      and here is my first page ASPAssignmentas p


      <html>
      <head>
      <title>Dispal y on same page</title>

      <script language=javasc ript >

      function DateExists(valu e)
      {
      d = new Date()
      var year = value.substring (value.lastInde xOf("/")+1);
      var date = value.substring (value.indexOf( "/")+1 , value.lastIndex Of("/"));
      var month = value.substring (0,value.indexO f("/"));

      if( month == 4 || month == 6 || month == 9 || month == 11 )
      {
      if(date > 30) { return false; }
      else {return true;}
      }
      else if (month == 2)
      {
      if ( year%4 == 0 )
      {
      if (date > 29) { return false;}
      else {return true;}
      }
      else
      {
      if (date > 28) { return false;}
      else { return true; }
      }
      }
      else if( month ==1 || month == 3|| month ==5 || month == 7 || month == 8 || month == 10 || month == 12)
      {
      if ( date >31) { return false; }
      else {return true; }
      }



      }


      function validate()
      {

      var str=""
      if(document.get ElementById("tx tName").value== "")
      {
      str+="Name can not be blank \n"
      }
      if (document.getEl ementById("txtD OB").value==" ")
      {
      str+="Please enter date of birth \n"
      }
      else
      {
      var RegularExpressi on = /^([0][1-9]|[1-9]|[1][0-2])(\/)([0][1-9]|[1-9]|[1-2][0-9]|[3][0-1])(\/)([0-9]{4})$/;

      if (RegularExpress ion.test(docume nt.getElementBy Id("txtDOB").va lue)!=true)
      {
      str+="Please enter a correct value in the date field \n"+ "the date must be in the format MM/DD/YYYY \n"
      }
      }

      if (DateExists(doc ument.getElemen tById("txtDOB") .value)==false)
      {
      str+="Date entered as date of birth do not exist \n"
      }

      if (document.getEl ementById("Male ").checked == false && document.getEle mentById("Femal e").checked == false )
      {
      str+="Please select gender \n"
      }

      value=document. getElementById( "txtDOB").v alue
      var year = value.substring (value.lastInde xOf("/")+1);

      if (d.getFullYear( ) < parseInt(year)+ parseInt(18))
      {
      str+="age must be greater than 18 years \n"
      }
      if(document.get ElementById("tx tAddress").valu e=="")
      {
      str+="Address can not be blank \n"
      }

      if(str!="")
      {
      alert("Please correct the following(s) : \n\n" + str)
      // window.location .reload();
      return false
      }

      }



      </script>


      <%
      set Conn = server.createob ject("adodb.con nection")
      Conn.Open "driver={sq l server}; server=SERVER NAME; database=DATABA SE; uid=UID; pwd=PASSWORD;"

      set rs=Server.Creat eObject("ADODB. recordset")
      rs.Open "Select * from TABLE ", conn
      response.Write( "<P>")

      %>

      <%


      if(rs.EOF<>true ) then

      select case (rs("degree"))

      case "BE"
      BE="selected"
      case "B.TECH"
      BTECH="selected "
      case "MCA"
      MCA="selected"
      case "MBA"
      MBA="selected"
      case "M.TECH"
      MTECH="selected "

      end select




      select case (rs("gender"))
      case "Male"
      m="checked"
      case "Female"
      f="checked"
      end select

      end if

      %>


      </head>

      <body style="font-family:Verdana ; font-size:smaller ">




      <form id="form1" method=get action="ASPAssi gnment2.asp" >
      <br />
      <table style="font-family:Verdana; font-size:10pt ">
      <tr>
      <td align="right" > Name : </td>
      <td><input type=text id=txtName name=Name value="<%if (rs.EOF<>true)t hen response.Write( rs("Name")) end if%>" style="width: 300px" /></td>
      </tr>
      <tr>
      <td align="right">D OB : </td>
      <td><input type=text id=txtDOB name=DOB value="<%if (rs.EOF<>true)t hen response.Write( rs("dob")) end if%>" style="width: 300px" /></td>
      </tr>
      <tr>
      <td align="right"> Gender : </td>
      <td><input type=radio value=Male <%=m %> id=Male name=Gender style="width: 25px" />Male &nbsp; &nbsp; &nbsp;
      <input type=radio value=Female <%=f %> id=Female name=Gender style="width: 25px" /> Female </td>
      </tr>
      <tr>
      <td align="right"> Qualification : </td>
      <td><select style="width: 300px" id= ddlDegree name=degree>
      <option value="BE" <%=BE %> >BE</option>
      <option value="B.TECH" <%=BTECH %>>B TECH</option>
      <option value="MCA" <%=MCA %>>MCA</option>
      <option value="MBA" <%=MBA %>>MBA</option>
      <option value="M.TECH" <%=MTECH %>>M TECH</option>
      </select></td>
      </tr>
      <tr>
      <td align="right">A ddress :</td>
      <td><input type=text id=txtAddress name=address value="<%if (rs.EOF<>true)t hen response.Write( rs("address")) end if%>" style="width: 300px" /></td>
      </tr>

      <tr>
      <td align="right"></td>
      <td><input type=submit name=submit value="Submit" onclick="return validate()" style="font-size: x-small; font-family: Verdana"/></td>

      </tr>

      </table>
      <br />
      </form>

      <%



      do while not rs.EOF
      for each x in rs.fields

      response.write( x.name)
      response.write( " = ")
      response.write( x.value)
      response.Write( "<br>")

      next

      rs.MoveNext
      Response.Write( "<br><br>")

      loop
      conn.Close

      %>

      </body>
      </html>

      Comment

      • gotonagle
        New Member
        • Nov 2007
        • 19

        #4
        now i have done this for doing on the same page all the things. now problem is solved but pls let me know if i can do better that this.(pls dont check for nameing conventions ..its my learning application...i know it is little difficult to understand due ot lack of that/...)
        pls consider...
        thnx again



        <html>
        <head >
        <title>Move </title>

        <script language=javasc ript >

        function DateExists(valu e)
        {
        d = new Date()
        var year = value.substring (value.lastInde xOf("/")+1);
        var date = value.substring (value.indexOf( "/")+1 , value.lastIndex Of("/"));
        var month = value.substring (0,value.indexO f("/"));

        if( month == 4 || month == 6 || month == 9 || month == 11 )
        {
        if(date > 30) { return false; }
        else {return true;}
        }
        else if (month == 2)
        {
        if ( year%4 == 0 )
        {
        if (date > 29) { return false;}
        else {return true;}
        }
        else
        {
        if (date > 28) { return false;}
        else { return true; }
        }
        }
        else if( month ==1 || month == 3|| month ==5 || month == 7 || month == 8 || month == 10 || month == 12)
        {
        if ( date >31) { return false; }
        else {return true; }
        }



        }


        function validate()
        {

        var str=""
        if(document.get ElementById("na me").value==" ")
        {
        str+="Name can not be blank \n"
        }
        if (document.getEl ementById("dob" ).value=="")
        {
        str+="Please enter date of birth \n"
        }
        else
        {
        var RegularExpressi on = /^([0][1-9]|[1-9]|[1][0-2])(\/)([0][1-9]|[1-9]|[1-2][0-9]|[3][0-1])(\/)([0-9]{4})$/;

        if (RegularExpress ion.test(docume nt.getElementBy Id("dob").value )!=true)
        {
        str+="Please enter a correct value in the date field \n"+ "the date must be in the format MM/DD/YYYY \n"
        }
        }

        if (DateExists(doc ument.getElemen tById("dob").va lue)==false)
        {
        str+="Date entered as date of birth do not exist \n"
        }

        if (document.getEl ementById("Male ").checked == false && document.getEle mentById("Femal e").checked == false )
        {
        str+="Please select gender \n"
        }

        value=document. getElementById( "dob").valu e
        var year = value.substring (value.lastInde xOf("/")+1);

        if (d.getFullYear( ) < parseInt(year)+ parseInt(18))
        {
        str+="age must be greater than 18 years \n"
        }
        if(document.get ElementById("ad dress").value== "")
        {
        str+="Address can not be blank \n"
        }

        if(str!="")
        {
        alert("Please correct the following(s) : \n\n" + str)

        return false
        }

        }


        </script>


        <% if (session("count ")="" or session("count" )=0)then
        session("count" )=0
        end if
        dim total
        total = 0
        set Conn = server.createob ject("adodb.con nection")
        Conn.Open "driver={sq l server}; server=SERVER; database=DATABA SE; uid=UID; pwd=PASSWORD;"
        set rs=Server.Creat eObject("ADODB. recordset")

        rs.Open "Select * from TABLE ", conn

        do while not rs.EOF
        rs.MoveNext
        total=total+1
        loop
        rs.Close

        rs.Open "Select * from TABLE ", conn

        if (request.Form(" button")="next" and rs.EOF<>true) then
        if( session("count" )<total-1) then
        session("count" )=session("coun t")+1
        rs.Move(session ("count"))
        else
        rs.Move(total-1)
        response.Write( "you are on last record")
        end if
        // response.Write( rs("name"))
        end if

        if (request.Form(" button")="prev" and rs.EOF<>true) then
        if(session("cou nt")>0) then
        session("count" )=session("coun t")-1
        rs.Move(session ("count"))
        else
        rs.Move(session ("count"))
        Response.Write( "you are on first record")
        end if
        // response.Write( rs("name"))
        end if

        if (request.Form(" button")="First " and rs.EOF<>true) then
        session("count" )=0
        rs.Move(session ("count"))
        // response.Write( rs("name"))
        end if

        if (request.Form(" button")="Last" and rs.EOF<>true ) then
        session("count" )=total-1
        rs.Move(session ("count"))
        // response.Write( session("name") )
        end if



        %>

        </head>
        <body style="font-family:Verdana; font-size:smaller" >
        <form name=form id= form method=post style="font-family:Verdana; font-size:smaller" >
        <table style="font-family:Verdana; font-size:10pt " >
        <tr>
        <td> Name :</td><td><input type=text name=name id=name value = "<%if(rs.eof<>t rue)then response.write( rs("name"))end if%>" style="width: 296px" /></td> <br />
        </tr>
        <tr>
        <td>DOB :</td><td><input type=text name=dob id=dob value = "<%if(rs.eof<>t rue)then response.write( rs("dob"))end if%>" style="width: 296px" /></td><br />
        </tr>
        <tr>
        <td>Gender :</td><td><input type=radio value=Male <%if(rs.eof<>tr ue) then if(rs("gender") ="Male") then response.write( "checked") end if end if%> id=Male name=Gender style="width: 25px" />Male &nbsp; &nbsp; &nbsp;
        <input type=radio value=Female <%if(rs.eof<>tr ue) then if(rs("gender") )="Female" then response.write( "checked") end if end if%> id=Female name=Gender style="width: 25px" /> Female</td> <br />
        </tr>
        <tr>
        <td> Degree:</td><td> <select style="width: 300px" id= ddlDegree name=degree>
        <option value="BE"<%if( rs.eof<>true) then if(rs("degree") ="BE") then response.write( "Selected") end if end if%> >BE</option>
        <option value="B.TECH" <%if(rs.eof<>tr ue) then if(rs("degree") ="B.TECH") then response.write( "Selected") end if end if%>>B TECH</option>
        <option value="MCA" <%if(rs.eof<>tr ue) then if(rs("degree") ="MCA") then response.write( "Selected") end if end if%>>MCA</option>
        <option value="MBA" <%if(rs.eof<>tr ue) then if(rs("degree") ="MBA") then response.write( "Selected") end if end if%>>MBA</option>
        <option value="M.TECH"< %if(rs.eof<>tru e) then if(rs("degree") ="M.TECH") then response.write( "Selected") end if end if%>>M TECH</option>
        </select></td>
        </tr>
        <TR>
        <td>Address:</td><td> <input type=text name="address" id=address value = "<%if(rs.eof<>t rue)then response.write( rs("address"))e nd if%>" style="width: 298px" /></td><br />
        </TR>
        <tr><td></td><td>
        <input type=submit name=button id=btnFirst value="First" style="width: 70px" />
        <input type=submit name=button id=btnPrev value="prev" style="width: 70px" />
        <input type=submit name=button id=btnNext value="next" style="width: 70px" />
        <input type=submit name=button id=btnLast value="Last" style="width: 70px" />
        <input type=submit name=button id=btnInsert value="Insert" onclick="return validate()" style="width: 70px" /></td>
        </TR>
        </table>
        </form>

        <br />

        </body>
        </html>

        <%

        rs.Close

        rs.Open "Select * from TABLE ", conn
        do while not rs.EOF
        for each x in rs.fields
        response.write( x.name )
        response.write( " = ")
        response.write( x.value)
        response.Write( "<br>")
        next

        rs.MoveNext
        Response.Write( "<br><br>")

        loop
        rs.Close
        conn.Close

        %>
        <%

        if (request.Form(" button")="Inser t") then

        set Conn = server.createob ject("adodb.con nection")
        Conn.Open "driver={sq l server}; server=SERVER; database=DATABA SE; uid=UID; pwd=PASSWORD;"

        sql="INSERT INTO info VALUES"
        sql=sql & "( '" & Request.Form("N ame") & "',"
        sql=sql & "'" & Request.form("d ob") & "',"
        sql=sql & "'" & Request.form("g ender") & "',"
        sql=sql & "'" & Request.form("d egree") & "',"
        sql=sql & "'" & Request.form("a ddress") & "')"


        conn.Execute sql
        conn.close
        Response.redire ct("Move.asp")

        end if

        %>

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          I think I would have taken a slightly different approach, when you click the submit button a new input is added named "submit" and it is given the value of whatever value the submit has, so if you had the following as your submit button: [code=html]<input type="submit" name="submit" value="submit">[/html] and then you check for this value before you do the update, you will get the correct result: [code=asp]if request("submit ") <> "" then
          'do the update
          end if[/code]now if the user might hit the "refresh" button accidentally after submitting the form and you want to prevent re-entering the data you might do it like this:
          [code=asp]if request("submit ") <> "" then
          if formatDateTime( session("lastUp date"),2) = formatDateTime( date(), 2) then
          'info was already updated today, so ignore
          else
          session("lastUp date") = now()
          'do update
          end if
          end if[/code]Jared

          Comment

          • gotonagle
            New Member
            • Nov 2007
            • 19

            #6
            hi jared
            thnx for ur interest in this
            but do yu think it would be a good approch. it wont allow the user to insert any value again on the same browser. i wnated to do that also...
            what i m doinng now is to disabled insert button and adding a new button to ie 'add new value' and which resetal the fields and then enabled insert button..
            and also i can not make insert button's value as submit coz i have more butons on my page ie. prev, next , first and last u can see in the code..updated code is here .. pls go through that pls let me know i m going wrong...or any better can be done.........
            thnx again!
            [code=asp]
            <%@ LANGUAGE="VBSCR IPT" %>
            <% OPTION EXPLICIT %>


            <%
            'CHECKING FOR THE FIRST RUN FOR THE SESSION
            if (session("nRowI D")="" or session("nRowID ")=0)then
            session("nRowID ")=0
            end if

            dim m_nTotNoOfRecor ds, m_connADOASP, m_rsInfo, m_sQuery
            m_nTotNoOfRecor ds = 0
            set m_connADOASP = server.createob ject("ADODB.con nection")
            set m_rsInfo=Server .CreateObject(" ADODB.recordset ")

            session("lastpd ated")=now
            response.Write( formatDateTime( session("lastUp date"),2) )

            m_connADOASP.Op en "driver={sq l server}; server=rahul\sq lexpress; database=ADOASP ; uid=sa; pwd=;"
            m_rsInfo.Open "SELECT id, name, dob, gender, degree, address FROM Info ", m_connADOASP

            if (request.Form(" button")="Next" and m_rsInfo.EOF<>t rue) then
            if( session("nRowID ") < session("nTotNo OfRecords")-1) then 'IF POINTER IS NOT ON LAST RECORD'
            session("nRowID ")=session("nRo wID")+1
            m_rsInfo.Move(s ession("nRowID" ))
            else
            m_rsInfo.Move(s ession("nTotNoO fRecords")-1)
            response.Write( "you are on last record")
            end if
            end if

            if (request.Form(" button")="Prev" and m_rsInfo.EOF<>t rue) then
            if(session("nRo wID")>0) then ' IF POINTER IS NOT ON FIRST RECORD'
            session("nRowID ")=session("nRo wID")-1
            m_rsInfo.Move(s ession("nRowID" ))
            else
            m_rsInfo.Move(s ession("nRowID" ))
            Response.Write( "you are on first record")
            end if
            end if

            if (request.Form(" button")="First " and m_rsInfo.EOF<>t rue) then
            session("nRowID ")=0
            m_rsInfo.Move(s ession("nRowID" ))
            end if

            if (request.Form(" button")="Last" and m_rsInfo.EOF<>t rue ) then
            session("nRowID ")=session("nTo tNoOfRecords")-1
            m_rsInfo.Move(s ession("nRowID" ))
            end if


            %>

            <html>
            <head >
            <title>Move </title>

            <script language=javasc ript >
            <%
            'FUNCTION IS CHECKING FOR THE DATE IF EXISTS IN THE CALENDER
            %>
            function DateExists(valu e)
            {
            d = new Date()
            var year = value.substring (value.lastInde xOf("/")+1);
            var date = value.substring (value.indexOf( "/")+1 , value.lastIndex Of("/"));
            var month = value.substring (0,value.indexO f("/"));

            if( month == 4 || month == 6 || month == 9 || month == 11 )
            {
            if(date > 30) { return false; }
            else {return true;}
            }
            else if (month == 2)
            {
            if ( year%4 == 0 )
            {
            if (date > 29) { return false;}
            else {return true;}
            }
            else
            {
            if (date > 28) { return false;}
            else { return true; }
            }
            }
            else if( month ==1 || month == 3|| month ==5 || month == 7 || month == 8 || month == 10 || month == 12)
            {
            if ( date >31) { return false; }
            else {return true; }
            }



            }

            <%
            'PERFORMING VALIDATION BEFORE INSERTION INTO DATABASE
            %>
            function validate()
            {

            var str=""
            if(document.get ElementById("na me").value==" ")
            {
            str+="Name can not be blank \n"
            }
            if (document.getEl ementById("dob" ).value=="")
            {
            str+="Please enter date of birth \n"
            }
            else
            {
            var RegularExpressi on = /^([0][1-9]|[1-9]|[1][0-2])(\/)([0][1-9]|[1-9]|[1-2][0-9]|[3][0-1])(\/)([0-9]{4})$/;

            if (RegularExpress ion.test(docume nt.getElementBy Id("dob").value )!=true)
            {
            str+="Please enter a correct value in the date field \n"+ "the date must be in the format MM/DD/YYYY \n"
            }
            }

            if (DateExists(doc ument.getElemen tById("dob").va lue)==false)
            {
            str+="Date entered as date of birth do not exist \n"
            }

            if (document.getEl ementById("Male ").checked == false && document.getEle mentById("Femal e").checked == false )
            {
            str+="Please select gender \n"
            }

            value=document. getElementById( "dob").valu e
            var year = value.substring (value.lastInde xOf("/")+1);

            if (d.getFullYear( ) < parseInt(year)+ parseInt(18))
            {
            str+="age must be greater than 18 years \n"
            }
            if(document.get ElementById("ad dress").value== "")
            {
            str+="Address can not be blank \n"
            }

            if(str!="")
            {
            alert("Please correct the following(s) : \n\n" + str)
            // window.location .reload();
            return false
            }

            }

            function funResetControl s()
            {
            document.getEle mentById("name" ).value=""
            document.getEle mentById("dob") .value=""
            document.getEle mentById("addre ss").value=""
            document.getEle mentById("Male" ).checked=false
            document.getEle mentById("Femal e").checked=fal se
            document.getEle mentById("degre e").value="B E"
            document.getEle mentById("btnIn sert").disabled =false
            }

            </script>


            </head>
            <body style="font-family:Verdana; font-size:smaller" >
            <form name=form id= form method=post style="font-family:Verdana; font-size:smaller" >
            <table style="font-family:Verdana; font-size:10pt" >
            <tr>
            <td> Name :</td><td><input type=text name=name id=name value = "<%if(m_rsInfo. eof<>true)then response.write( m_rsInfo.fields ("name").value) end if%>" style="width: 296px" /></td> <br />
            </tr>
            <tr>
            <td>DOB :</td><td><input type=text name=dob id=dob value = "<%if(m_rsInfo. eof<>true)then response.write( m_rsInfo.fields ("dob").value)e nd if%>" style="width: 296px" /></td><br />
            </tr>
            <tr>
            <td>Gender :</td><td><input type=radio value=Male <%if(m_rsInfo.e of<>true) then if(m_rsInfo.fie lds("gender").v alue="Male") then response.write( "checked") end if end if%> id=Male name=Gender style="width: 25px" />Male &nbsp; &nbsp; &nbsp;
            <input type=radio value=Female <%if(m_rsInfo.e of<>true) then if(m_rsInfo.fie lds("gender").v alue)="Female" then response.write( "checked") end if end if%> id=Female name=Gender style="width: 25px" /> Female</td> <br />
            </tr>
            <tr>
            <td> Degree:</td><td> <select style="width: 300px" id= ddlDegree name=degree>
            <option value="BE"<%if( m_rsInfo.eof<>t rue) then if(m_rsInfo.fie lds("degree").v alue="BE") then response.write( "Selected") end if end if%> >BE</option>
            <option value="B.TECH" <%if(m_rsInfo.e of<>true) then if(m_rsInfo.fie lds("degree").v alue="B.TECH") then response.write( "Selected") end if end if%>>B TECH</option>
            <option value="MCA" <%if(m_rsInfo.e of<>true) then if(m_rsInfo.fie lds("degree").v alue="MCA") then response.write( "Selected") end if end if%>>MCA</option>
            <option value="MBA" <%if(m_rsInfo.e of<>true) then if(m_rsInfo.fie lds("degree").v alue="MBA") then response.write( "Selected") end if end if%>>MBA</option>
            <option value="M.TECH"< %if(m_rsInfo.eo f<>true) then if(m_rsInfo.fie lds("degree").v alue="M.TECH") then response.write( "Selected") end if end if%>>M TECH</option>
            </select></td>
            </tr>
            <TR>
            <td>Address:</td><td> <input type=text name="address" id=address value = "<%if(m_rsInfo. eof<>true)then response.write( m_rsInfo.fields ("address").val ue)end if%>" style="width: 298px" /></td><br />
            </TR>
            <tr><td></td><td>
            <input type=submit name=button id=btnFirst value="First" style="width: 70px" />
            <input type=submit name=button id=btnPrev value="Prev" style="width: 70px" />
            <input type=submit name=button id=btnNext value="Next" style="width: 70px" />
            <input type=submit name=button id=btnLast value="Last" style="width: 70px" />
            </td>
            </TR>
            <tr>
            <td></td>
            <td><input type=button name=btnAddNew id=btnAddNew value="Add New Value" onclick="funRes etControls()" style="width: 103px"/>
            <input type=submit name=button id=btnInsert value="Insert" onclick="return validate()" style="width: 103px" disabled="disab led" /></td>
            </tr>
            </table>
            </form>

            <br />

            </body>
            </html>

            <%

            m_rsInfo.Close

            'DISPLAY ALL THE RECORDS ON THE PAGE
            m_rsInfo.Open "SELECT id, name, dob, gender, degree, address FROM Info ", m_connADOASP
            dim x
            do while not m_rsInfo.EOF
            for each x in m_rsInfo.fields
            response.write( x.name )
            response.write( " = ")
            response.write( x.value)
            response.Write( "<br>")
            next

            m_rsInfo.MoveNe xt
            m_nTotNoOfRecor ds=m_nTotNoOfRe cords+1
            Response.Write( "<br><br>")

            loop
            session("nTotNo OfRecords")= m_nTotNoOfRecor ds
            m_rsInfo.Close
            m_connADOASP.Cl ose

            %>
            <%

            if (request.Form(" button")="Inser t") then

            set m_connADOASP = server.createob ject("adodb.con nection")
            m_connADOASP.Op en "driver={sq l server}; server=rahul\sq lexpress; database=ADOASP ; uid=sa; pwd=;"

            m_sQuery="INSER T INTO info VALUES"
            m_sQuery=m_sQue ry & "( '" & Request.Form("N ame") & "',"
            m_sQuery=m_sQue ry & "'" & Request.form("d ob") & "',"
            m_sQuery=m_sQue ry & "'" & Request.form("g ender") & "',"
            m_sQuery=m_sQue ry & "'" & Request.form("d egree") & "',"
            m_sQuery=m_sQue ry & "'" & Request.form("a ddress") & "')"


            m_connADOASP.Ex ecute m_sQuery
            m_connADOASP.cl ose
            Response.redire ct("Move.asp")

            end if

            %>[/code]

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #7
              You have just posted over 250 lines of code. It is very difficult to read through someone else's code for that long. It would be much easier if you posted two or three lines to illustrate your problem.
              Code:
              if condition
              'you don't need to give the update code unless you want me to look specifically atr that
              end if
              by the way, please remember to put your code in code tags - there is a button marked # which places code within the correct tags.

              My code was just a simple example of one way to restrict user updates. There are hundreds of ways to do it, but essentially they will all use if...then statements to determine if a value should be updated or if the info was sent inadvertantly.

              I don't want to read through your whole code, but if you have a specific question, post the part of the code that is giving you trouble.

              Jared

              Comment

              • gotonagle
                New Member
                • Nov 2007
                • 19

                #8
                hi jared
                sorry for any inconvienvience . as i m new to all this and i m not familier with all this..and i m learnig asp.
                but thnx for your help...i m not facing any prob in this now...insertion/navigation all is working..but i think thwrw may be some better way.... my question is that ur previos code wont allow me to insert a new value again into same browser...right ??..does it??...
                so i was asking for any better solution....

                thnx again

                rahul

                Comment

                • jhardman
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3405

                  #9
                  Rahul,

                  hey, we don't have a character limit, so there is no reason to use SMS speak like "ur" instead of "your". People who don't spend a lot of time SMSing have a hard time understanding that, so we ask people to use as correct English as they can manage when they post here.

                  Back to your question... the code snippet I gave does indeed limit users to one update per day per session, but any ASP solution is going to look very similar. You will need to decide the best way to distinguish between desired updates and undesired, and make the only updates happen when you want it to. There are a million ways to do this, you will need to come up with the best solution for you. For example, you could have the submit button disabled unless a change has been made- this could be handled quite easily with javascript, and if the page was refreshed, the submit button would be disabled again.

                  Jared

                  Comment

                  • gotonagle
                    New Member
                    • Nov 2007
                    • 19

                    #10
                    hi Jared
                    Thank you very much for your lots of lots of help.......
                    i have done this already. you can check that if you go through the code(i know you wont like to go through that all and reason is obvious) ok leave that all. i made a new button 'Add New Value" that enabled the "insert" button and reset all the controls. and also performing validations before insertion on the page for nulll values and special characters..
                    now on page load i have disabled "insert" button. here is the specific code for insert operation.

                    Code:
                    if (request.Form("button")="Insert") then
                            
                               set m_connmyASP = server.createobject("adodb.connection")
                               m_connmyASP.Open "driver={sql server}; server=SERVER; database=DATABASE; uid=UID; pwd=PWD;"  
                             
                               m_sQuery="INSERT INTO info VALUES"
                               m_sQuery=m_sQuery & "( '" & Request.Form("Name") & "',"
                               m_sQuery=m_sQuery & "'" & Request.form("dob") & "',"
                               m_sQuery=m_sQuery & "'" & Request.form("gender") & "',"
                               m_sQuery=m_sQuery & "'" & Request.form("degree") & "',"
                               m_sQuery=m_sQuery & "'" & Request.form("address") & "')"
                                
                          
                               m_connmyASP.Execute m_sQuery
                               m_connmyASP.close
                               Response.redirect("Move.asp")
                           
                        end if
                    now problem here is that i have to redirect it to the same page again at last.. means again whole post back whole page load and everything..if i do not use this then "request.form(" button").value" always remains same ie "Insert" for page refresh...the insertion performed on each refresh even "insert" button is disabled.

                    can you please tell if we can do anything better.
                    and i will try to use proper english from the next time.
                    thanks again

                    Rahul

                    Comment

                    • gotonagle
                      New Member
                      • Nov 2007
                      • 19

                      #11
                      hi Jared
                      can you please help in this regard also
                      http://www.thescripts. com/forum/thread743115.ht ml
                      i have posted this before.

                      thank .
                      Rahul

                      Comment

                      • jhardman
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3405

                        #12
                        Most websites handle this problem by posting a large warning near the submit button, or visible just after the "submit" has been pressed which reads: "Do not click 'Refresh'. This will insert a duplicate record." But there are other ways around it. The best way I can think of you can only use on one condition. Is there any possibility that a particular record should be duplicated exactly? if not, then I would do it like this:

                        instead of inserting a record with the "insert" statement, use a "select" statement to open the this record:
                        Code:
                        query = "SELECT * FROM myTable WHERE name = '" & Request.Form("Name") & "' AND gender = '" & Request.form("gender") & "' AND degree = '" & Request.form("degree") & "' AND address = '" & Request.form("address") & "'"
                        then you check to see if the query returns any records
                        Code:
                        if rs.EOF then
                           'no records returned
                           rs.addNew
                           rs("name") = request.form("name")
                           'etc
                           rs.update
                        else
                           'record is already in the db, user must have hit the refresh button
                           response.write "Hey, blockhead, this record is already in the db!"
                        end if
                        Would this work for you?

                        Jared

                        Comment

                        Working...