473,549 Members | 4,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check for page refresh and page submit?

19 New Member
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
11 12971
JamieHowarth0
533 Recognized Expert Contributor
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
gotonagle
19 New Member
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>
Dec 5 '07 #3
gotonagle
19 New Member
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

%>
Dec 5 '07 #4
jhardman
3,406 Recognized Expert Specialist
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
gotonagle
19 New Member
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
3,406 Recognized Expert Specialist
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
gotonagle
19 New Member
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
3,406 Recognized Expert Specialist
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
gotonagle
19 New Member
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

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

Similar topics

27
7091
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate a user from information you got from the session. Each secure app on a site must challenge the user for name and password, each and every time the...
6
3317
by: laura | last post by:
I'm doing a page which gathers some text in the form of a text box in a <form>. This text is saved to a text file, notices.txt and I want to be able to display the saved text on the page, as soon as they click the SUBMIT button - is this possible? At the moment I have a hyperlink called "back" which, once they have entered the text and they...
6
3967
by: iwearwatches | last post by:
Group, What a root canal. Here is what I have: I have a page that has several layers that I will either show/hide based on a graphic/tab that the user clicks. (works perfectly)
5
5180
by: Bill Cohagan | last post by:
I'm constructing an ASP app with a frameset on the home html page. From frame A I need to referesh the page in frame B when a button click occurs on a button in Frame A (server side event handler). To accomplish this I've included some client side script in the page being built in frame A such that whenever it is received by the browser it...
18
10112
by: Alan Z. Scharf | last post by:
1. I have a chain of six asynch callbacks initiated by a button, and want the page to refresh at the end of each callback to display A. Results of a SQLServer query showing cumulative running time, and B. A progress bar. 2. I have this working with a refresh timer: <META http-equiv="refresh" content="5">
2
6467
by: Mike Moore | last post by:
Is there an easy way to check if Java Script is enabled in the MS Internet Explorer browser for versions 5.0 and above? Also, how might I test this?
0
1088
by: Ambush | last post by:
My aspx is called from an ASP page. I process the request and then call another ASP page with a few hidden inputs. Currently, when the page processes, the user is complaining that my code is running too fast and that my "Please Wait" page flashes by too quickly. I can't put an inline wait/sleep command, as the page doesn't refresh until the...
1
2703
by: Ibrahim. | last post by:
Hi, I have a login page, the problem I'm facing is like this; 1. Login page with submit button (being default button); 2. When first time the page is submitted then submit code is called. 3. Again when page refresh is done by (f5) then submit button is fired implicitly.
4
5044
by: Dan | last post by:
Hi, i'm not sure to understand the difference between refreshing the pagina by clicking on 'refresh' in the browser and a postback. What i think it is: Suppose a page with a form containing a textbox and a dropdowlist: and a button to start something n code-behind: a refresh doesn't send any value back to the server but with a postback,...
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7480
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.