By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,786 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,786 IT Pros & Developers. It's quick & easy.

how to check for page refresh and page submit?

P: 19
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
Dec 3 '07 #1
Share this Question
Share on Google+
11 Replies


codegecko
Expert 100+
P: 533
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
Dec 3 '07 #2

P: 19
hi
thnx for ur interesr in prob

it was my insert .asp


<html>
<head>
<title>Dispaly on same page</title>
</head>
<body >
<form>

</form>

<%

set Conn = server.createobject("adodb.connection")
Conn.Open "driver={sql server}; server=SERVERNAME; database=DATABASE; uid=UID; pwd=PASSWORD;"

sql="INSERT TABLE info VALUES"
sql=sql & "( '" & Request.Form("Name") & "',"
sql=sql & "'" & Request.Form("dob") & "',"
sql=sql & "'" & Request.Form("gender") & "',"
sql=sql & "'" & Request.Form("degree") & "',"
sql=sql & "'" & Request.Form("address") & "')"


conn.Execute sql,recAffected
Response.write("inserted!!!!!!!!!!!!!!!")
conn.close
Response.redirect("ASPAssignment2.asp")

%>


</body>
</html>

and here is my first page ASPAssignmentasp


<html>
<head>
<title>Dispaly on same page</title>

<script language=javascript >

function DateExists(value)
{
d = new Date()
var year = value.substring(value.lastIndexOf("/")+1);
var date = value.substring(value.indexOf("/")+1 , value.lastIndexOf("/"));
var month = value.substring(0,value.indexOf("/"));

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.getElementById("txtName").value=="")
{
str+="Name can not be blank \n"
}
if (document.getElementById("txtDOB").value=="")
{
str+="Please enter date of birth \n"
}
else
{
var RegularExpression = /^([0][1-9]|[1-9]|[1][0-2])(\/)([0][1-9]|[1-9]|[1-2][0-9]|[3][0-1])(\/)([0-9]{4})$/;

if (RegularExpression.test(document.getElementById("t xtDOB").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(document.getElementById("txtDOB").valu e)==false)
{
str+="Date entered as date of birth do not exist \n"
}

if (document.getElementById("Male").checked == false && document.getElementById("Female").checked == false )
{
str+="Please select gender \n"
}

value=document.getElementById("txtDOB").value
var year = value.substring(value.lastIndexOf("/")+1);

if (d.getFullYear() < parseInt(year)+ parseInt(18))
{
str+="age must be greater than 18 years \n"
}
if(document.getElementById("txtAddress").value=="" )
{
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.createobject("adodb.connection")
Conn.Open "driver={sql server}; server=SERVER NAME; database=DATABASE; uid=UID; pwd=PASSWORD;"

set rs=Server.CreateObject("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="ASPAssignment2.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)then response.Write(rs("Name")) end if%>" style="width: 300px" /></td>
</tr>
<tr>
<td align="right">DOB : </td>
<td><input type=text id=txtDOB name=DOB value="<%if (rs.EOF<>true)then 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">Address :</td>
<td><input type=text id=txtAddress name=address value="<%if (rs.EOF<>true)then 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>
Dec 5 '07 #3

P: 19
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=javascript >

function DateExists(value)
{
d = new Date()
var year = value.substring(value.lastIndexOf("/")+1);
var date = value.substring(value.indexOf("/")+1 , value.lastIndexOf("/"));
var month = value.substring(0,value.indexOf("/"));

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.getElementById("name").value=="")
{
str+="Name can not be blank \n"
}
if (document.getElementById("dob").value=="")
{
str+="Please enter date of birth \n"
}
else
{
var RegularExpression = /^([0][1-9]|[1-9]|[1][0-2])(\/)([0][1-9]|[1-9]|[1-2][0-9]|[3][0-1])(\/)([0-9]{4})$/;

if (RegularExpression.test(document.getElementById("d ob").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(document.getElementById("dob").value)= =false)
{
str+="Date entered as date of birth do not exist \n"
}

if (document.getElementById("Male").checked == false && document.getElementById("Female").checked == false )
{
str+="Please select gender \n"
}

value=document.getElementById("dob").value
var year = value.substring(value.lastIndexOf("/")+1);

if (d.getFullYear() < parseInt(year)+ parseInt(18))
{
str+="age must be greater than 18 years \n"
}
if(document.getElementById("address").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.createobject("adodb.connection")
Conn.Open "driver={sql server}; server=SERVER; database=DATABASE; uid=UID; pwd=PASSWORD;"
set rs=Server.CreateObject("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("count")+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("count")>0) then
session("count")=session("count")-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<>true)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<>true)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<>true) 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<>true) 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<>true) then if(rs("degree")="B.TECH") then response.write("Selected") end if end if%>>B TECH</option>
<option value="MCA" <%if(rs.eof<>true) then if(rs("degree")="MCA") then response.write("Selected") end if end if%>>MCA</option>
<option value="MBA" <%if(rs.eof<>true) then if(rs("degree")="MBA") then response.write("Selected") end if end if%>>MBA</option>
<option value="M.TECH"<%if(rs.eof<>true) 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<>true)then response.write(rs("address"))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" />
<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")="Insert") then

set Conn = server.createobject("adodb.connection")
Conn.Open "driver={sql server}; server=SERVER; database=DATABASE; uid=UID; pwd=PASSWORD;"

sql="INSERT INTO info VALUES"
sql=sql & "( '" & Request.Form("Name") & "',"
sql=sql & "'" & Request.form("dob") & "',"
sql=sql & "'" & Request.form("gender") & "',"
sql=sql & "'" & Request.form("degree") & "',"
sql=sql & "'" & Request.form("address") & "')"


conn.Execute sql
conn.close
Response.redirect("Move.asp")

end if

%>
Dec 5 '07 #4

jhardman
Expert 2.5K+
P: 3,405
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:
Expand|Select|Wrap|Line Numbers
  1. if request("submit") <> "" then
  2.    'do the update
  3. end if
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:
Expand|Select|Wrap|Line Numbers
  1. if request("submit") <> "" then
  2.    if formatDateTime(session("lastUpdate"),2) = formatDateTime(date(), 2) then
  3.       'info was already updated today, so ignore
  4.    else
  5.       session("lastUpdate") = now()
  6.       'do update
  7.    end if
  8. end if
Jared
Dec 5 '07 #5

P: 19
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!
Expand|Select|Wrap|Line Numbers
  1. <%@ LANGUAGE="VBSCRIPT" %>
  2. <% OPTION EXPLICIT %>
  3.  
  4.  
  5.   <% 
  6.         'CHECKING FOR THE FIRST RUN FOR THE SESSION
  7.      if (session("nRowID")="" or session("nRowID")=0)then 
  8.             session("nRowID")=0
  9.      end if
  10.  
  11.         dim m_nTotNoOfRecords, m_connADOASP, m_rsInfo, m_sQuery
  12.         m_nTotNoOfRecords = 0
  13.         set m_connADOASP = server.createobject("ADODB.connection")
  14.         set m_rsInfo=Server.CreateObject("ADODB.recordset")
  15.  
  16.         session("lastpdated")=now
  17.         response.Write(formatDateTime(session("lastUpdate"),2) )
  18.  
  19.         m_connADOASP.Open "driver={sql server}; server=rahul\sqlexpress; database=ADOASP; uid=sa; pwd=;"  
  20.         m_rsInfo.Open "SELECT id, name, dob, gender, degree, address FROM Info ", m_connADOASP
  21.  
  22.         if (request.Form("button")="Next" and m_rsInfo.EOF<>true) then
  23.             if( session("nRowID") < session("nTotNoOfRecords")-1) then 'IF POINTER IS NOT ON LAST RECORD'
  24.             session("nRowID")=session("nRowID")+1
  25.             m_rsInfo.Move(session("nRowID"))     
  26.             else
  27.             m_rsInfo.Move(session("nTotNoOfRecords")-1)
  28.             response.Write("you are on last record")
  29.             end if
  30.         end if
  31.  
  32.         if (request.Form("button")="Prev"  and m_rsInfo.EOF<>true) then
  33.             if(session("nRowID")>0) then ' IF POINTER IS NOT ON FIRST RECORD'
  34.             session("nRowID")=session("nRowID")-1
  35.             m_rsInfo.Move(session("nRowID")) 
  36.             else
  37.             m_rsInfo.Move(session("nRowID"))
  38.             Response.Write("you are on first record")
  39.             end if
  40.         end if
  41.  
  42.         if (request.Form("button")="First" and m_rsInfo.EOF<>true) then
  43.         session("nRowID")=0
  44.         m_rsInfo.Move(session("nRowID")) 
  45.         end if
  46.  
  47.         if (request.Form("button")="Last" and m_rsInfo.EOF<>true ) then
  48.             session("nRowID")=session("nTotNoOfRecords")-1
  49.             m_rsInfo.Move(session("nRowID"))
  50.         end if
  51.  
  52.  
  53.  %>
  54.  
  55. <html>
  56. <head >
  57.     <title>Move </title>
  58.  
  59.     <script language=javascript >
  60. <%
  61. 'FUNCTION IS CHECKING FOR THE DATE IF EXISTS IN THE CALENDER
  62.  %>    
  63. function DateExists(value)
  64.    {
  65.         d = new Date()
  66.         var year = value.substring(value.lastIndexOf("/")+1);
  67.         var date = value.substring(value.indexOf("/")+1 , value.lastIndexOf("/"));
  68.         var month = value.substring(0,value.indexOf("/"));
  69.  
  70.       if( month == 4 || month == 6 || month == 9 || month == 11 )
  71.         {
  72.             if(date > 30) { return false; }
  73.             else {return true;}
  74.         }
  75.         else if (month == 2)
  76.             {                
  77.                 if ( year%4 == 0 )
  78.                 {
  79.                     if (date > 29) { return false;}
  80.                     else {return true;}                                
  81.                 }
  82.                 else 
  83.                 {
  84.                     if (date > 28) { return false;}
  85.                     else  { return true; }                 
  86.                 }                
  87.             }
  88.         else if( month ==1 || month == 3|| month ==5 || month == 7 || month == 8 || month == 10 || month == 12)
  89.             {
  90.                 if ( date >31) { return false; }
  91.                 else {return true; }        
  92.             }
  93.  
  94.  
  95.  
  96.    }
  97.  
  98. <%
  99. 'PERFORMING VALIDATION BEFORE INSERTION INTO DATABASE
  100.  %>
  101. function validate()
  102. {
  103.  
  104.  var str=""
  105.     if(document.getElementById("name").value=="")
  106.         {
  107.         str+="Name can not be blank \n"
  108.         }
  109.     if (document.getElementById("dob").value=="")
  110.         {
  111.         str+="Please enter date of birth \n"
  112.         }
  113.     else
  114.         {
  115.         var RegularExpression = /^([0][1-9]|[1-9]|[1][0-2])(\/)([0][1-9]|[1-9]|[1-2][0-9]|[3][0-1])(\/)([0-9]{4})$/;
  116.  
  117.         if (RegularExpression.test(document.getElementById("dob").value)!=true)
  118.             {             
  119.             str+="Please enter a correct value in the date field \n"+ "the date must be in the format MM/DD/YYYY \n"
  120.             }
  121.         }
  122.  
  123.     if (DateExists(document.getElementById("dob").value)==false)
  124.         {
  125.         str+="Date entered as date of birth do not exist \n"
  126.         }
  127.  
  128.     if (document.getElementById("Male").checked == false && document.getElementById("Female").checked == false )
  129.         {
  130.         str+="Please select gender \n"
  131.         }
  132.  
  133.        value=document.getElementById("dob").value
  134.        var year = value.substring(value.lastIndexOf("/")+1);
  135.  
  136.     if (d.getFullYear() < parseInt(year)+ parseInt(18))
  137.         {
  138.          str+="age must be greater than 18 years \n"
  139.         }
  140.     if(document.getElementById("address").value=="")
  141.         {
  142.         str+="Address can not be blank \n"
  143.         }
  144.  
  145.      if(str!="")
  146.         {
  147.         alert("Please correct the following(s) : \n\n" + str)
  148. //          window.location.reload();  
  149.         return false
  150.         }
  151.  
  152. }
  153.  
  154.     function funResetControls()
  155.     {
  156.     document.getElementById("name").value=""
  157.     document.getElementById("dob").value=""
  158.     document.getElementById("address").value=""
  159.     document.getElementById("Male").checked=false
  160.     document.getElementById("Female").checked=false
  161.     document.getElementById("degree").value="BE"
  162.     document.getElementById("btnInsert").disabled=false
  163.     }
  164.  
  165.     </script>
  166.  
  167.  
  168.    </head> 
  169.    <body style="font-family:Verdana; font-size:smaller" >
  170.      <form name=form id= form method=post style="font-family:Verdana; font-size:smaller" >
  171.     <table style="font-family:Verdana; font-size:10pt" >
  172.     <tr>
  173.     <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 />
  174.      </tr>
  175.      <tr>
  176.      <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)end if%>" style="width: 296px" /></td><br />
  177.     </tr>
  178.     <tr>
  179.     <td>Gender :</td><td><input type=radio value=Male <%if(m_rsInfo.eof<>true) then if(m_rsInfo.fields("gender").value="Male") then response.write("checked") end if end if%> id=Male name=Gender style="width: 25px"  />Male &nbsp; &nbsp; &nbsp;
  180.             <input type=radio value=Female <%if(m_rsInfo.eof<>true) then if(m_rsInfo.fields("gender").value)="Female" then response.write("checked") end if end if%> id=Female  name=Gender style="width: 25px" /> Female</td> <br />
  181.     </tr>
  182.     <tr>
  183.     <td> Degree:</td><td> <select style="width: 300px" id= ddlDegree name=degree>  
  184.             <option value="BE"<%if(m_rsInfo.eof<>true) then if(m_rsInfo.fields("degree").value="BE") then response.write("Selected") end if end if%> >BE</option>
  185.             <option value="B.TECH" <%if(m_rsInfo.eof<>true) then if(m_rsInfo.fields("degree").value="B.TECH") then response.write("Selected") end if end if%>>B TECH</option>
  186.             <option value="MCA" <%if(m_rsInfo.eof<>true) then if(m_rsInfo.fields("degree").value="MCA") then response.write("Selected") end if end if%>>MCA</option>
  187.             <option value="MBA" <%if(m_rsInfo.eof<>true) then if(m_rsInfo.fields("degree").value="MBA") then response.write("Selected") end if end if%>>MBA</option>
  188.             <option value="M.TECH"<%if(m_rsInfo.eof<>true) then if(m_rsInfo.fields("degree").value="M.TECH") then response.write("Selected") end if end if%>>M TECH</option>
  189.          </select></td>
  190.     </tr>
  191.     <TR>
  192.     <td>Address:</td><td> <input type=text name="address" id=address value = "<%if(m_rsInfo.eof<>true)then response.write(m_rsInfo.fields("address").value)end if%>" style="width: 298px" /></td><br />
  193.     </TR>
  194. <tr><td></td><td>    
  195.      <input type=submit name=button id=btnFirst value="First" style="width: 70px" />
  196.      <input type=submit name=button id=btnPrev value="Prev" style="width: 70px" />
  197.      <input type=submit name=button id=btnNext value="Next" style="width: 70px" />
  198.      <input type=submit name=button id=btnLast value="Last" style="width: 70px" />
  199.      </td>
  200. </TR>
  201. <tr>
  202.     <td></td>
  203.     <td><input type=button name=btnAddNew id=btnAddNew value="Add New Value"  onclick="funResetControls()"  style="width: 103px"/>
  204.     <input type=submit name=button id=btnInsert value="Insert" onclick="return validate()" style="width: 103px" disabled="disabled" /></td>
  205. </tr>
  206.      </table>
  207.      </form>
  208.  
  209.  <br />
  210.  
  211. </body>
  212. </html>
  213.  
  214. <%
  215.  
  216.     m_rsInfo.Close
  217.  
  218.     'DISPLAY ALL THE RECORDS ON THE PAGE    
  219.     m_rsInfo.Open "SELECT id, name, dob, gender, degree, address FROM Info ", m_connADOASP
  220.     dim x
  221.     do while not m_rsInfo.EOF 
  222.         for each x in m_rsInfo.fields
  223.            response.write(x.name )
  224.            response.write(" = ")
  225.            response.write(x.value)
  226.            response.Write("<br>")
  227.         next
  228.  
  229.         m_rsInfo.MoveNext 
  230.         m_nTotNoOfRecords=m_nTotNoOfRecords+1
  231.         Response.Write("<br><br>")
  232.  
  233.     loop
  234.     session("nTotNoOfRecords")= m_nTotNoOfRecords
  235.     m_rsInfo.Close 
  236.     m_connADOASP.Close
  237.  
  238.  %>
  239. <%
  240.  
  241.     if (request.Form("button")="Insert") then
  242.  
  243.            set m_connADOASP = server.createobject("adodb.connection")
  244.            m_connADOASP.Open "driver={sql server}; server=rahul\sqlexpress; database=ADOASP; uid=sa; pwd=;"  
  245.  
  246.            m_sQuery="INSERT INTO info VALUES"
  247.            m_sQuery=m_sQuery & "( '" & Request.Form("Name") & "',"
  248.            m_sQuery=m_sQuery & "'" & Request.form("dob") & "',"
  249.            m_sQuery=m_sQuery & "'" & Request.form("gender") & "',"
  250.            m_sQuery=m_sQuery & "'" & Request.form("degree") & "',"
  251.            m_sQuery=m_sQuery & "'" & Request.form("address") & "')"
  252.  
  253.  
  254.            m_connADOASP.Execute m_sQuery
  255.            m_connADOASP.close
  256.            Response.redirect("Move.asp")
  257.  
  258.     end if
  259.  
  260.  %>
Dec 6 '07 #6

jhardman
Expert 2.5K+
P: 3,405
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.
Expand|Select|Wrap|Line Numbers
  1. if condition
  2. 'you don't need to give the update code unless you want me to look specifically atr that
  3. 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
Dec 6 '07 #7

P: 19
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
Dec 7 '07 #8

jhardman
Expert 2.5K+
P: 3,405
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
Dec 7 '07 #9

P: 19
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.

Expand|Select|Wrap|Line Numbers
  1. if (request.Form("button")="Insert") then
  2.  
  3.            set m_connmyASP = server.createobject("adodb.connection")
  4.            m_connmyASP.Open "driver={sql server}; server=SERVER; database=DATABASE; uid=UID; pwd=PWD;"  
  5.  
  6.            m_sQuery="INSERT INTO info VALUES"
  7.            m_sQuery=m_sQuery & "( '" & Request.Form("Name") & "',"
  8.            m_sQuery=m_sQuery & "'" & Request.form("dob") & "',"
  9.            m_sQuery=m_sQuery & "'" & Request.form("gender") & "',"
  10.            m_sQuery=m_sQuery & "'" & Request.form("degree") & "',"
  11.            m_sQuery=m_sQuery & "'" & Request.form("address") & "')"
  12.  
  13.  
  14.            m_connmyASP.Execute m_sQuery
  15.            m_connmyASP.close
  16.            Response.redirect("Move.asp")
  17.  
  18.     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
Dec 10 '07 #10

P: 19
hi Jared
can you please help in this regard also
http://www.thescripts.com/forum/thread743115.html
i have posted this before.

thank .
Rahul
Dec 10 '07 #11

jhardman
Expert 2.5K+
P: 3,405
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:
Expand|Select|Wrap|Line Numbers
  1. 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
Expand|Select|Wrap|Line Numbers
  1. if rs.EOF then
  2.    'no records returned
  3.    rs.addNew
  4.    rs("name") = request.form("name")
  5.    'etc
  6.    rs.update
  7. else
  8.    'record is already in the db, user must have hit the refresh button
  9.    response.write "Hey, blockhead, this record is already in the db!"
  10. end if
Would this work for you?

Jared
Dec 11 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.