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
11 12943
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
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
<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>
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
<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
%>
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: - if request("submit") <> "" then
-
'do the update
-
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: - if request("submit") <> "" then
-
if formatDateTime(session("lastUpdate"),2) = formatDateTime(date(), 2) then
-
'info was already updated today, so ignore
-
else
-
session("lastUpdate") = now()
-
'do update
-
end if
-
end if
Jared
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! -
<%@ LANGUAGE="VBSCRIPT" %>
-
<% OPTION EXPLICIT %>
-
-
-
<%
-
'CHECKING FOR THE FIRST RUN FOR THE SESSION
-
if (session("nRowID")="" or session("nRowID")=0)then
-
session("nRowID")=0
-
end if
-
-
dim m_nTotNoOfRecords, m_connADOASP, m_rsInfo, m_sQuery
-
m_nTotNoOfRecords = 0
-
set m_connADOASP = server.createobject("ADODB.connection")
-
set m_rsInfo=Server.CreateObject("ADODB.recordset")
-
-
session("lastpdated")=now
-
response.Write(formatDateTime(session("lastUpdate"),2) )
-
-
m_connADOASP.Open "driver={sql server}; server=rahul\sqlexpress; 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<>true) then
-
if( session("nRowID") < session("nTotNoOfRecords")-1) then 'IF POINTER IS NOT ON LAST RECORD'
-
session("nRowID")=session("nRowID")+1
-
m_rsInfo.Move(session("nRowID"))
-
else
-
m_rsInfo.Move(session("nTotNoOfRecords")-1)
-
response.Write("you are on last record")
-
end if
-
end if
-
-
if (request.Form("button")="Prev" and m_rsInfo.EOF<>true) then
-
if(session("nRowID")>0) then ' IF POINTER IS NOT ON FIRST RECORD'
-
session("nRowID")=session("nRowID")-1
-
m_rsInfo.Move(session("nRowID"))
-
else
-
m_rsInfo.Move(session("nRowID"))
-
Response.Write("you are on first record")
-
end if
-
end if
-
-
if (request.Form("button")="First" and m_rsInfo.EOF<>true) then
-
session("nRowID")=0
-
m_rsInfo.Move(session("nRowID"))
-
end if
-
-
if (request.Form("button")="Last" and m_rsInfo.EOF<>true ) then
-
session("nRowID")=session("nTotNoOfRecords")-1
-
m_rsInfo.Move(session("nRowID"))
-
end if
-
-
-
%>
-
-
<html>
-
<head >
-
<title>Move </title>
-
-
<script language=javascript >
-
<%
-
'FUNCTION IS CHECKING FOR THE DATE IF EXISTS IN THE CALENDER
-
%>
-
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; }
-
}
-
-
-
-
}
-
-
<%
-
'PERFORMING VALIDATION BEFORE INSERTION INTO DATABASE
-
%>
-
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("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(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)
-
// window.location.reload();
-
return false
-
}
-
-
}
-
-
function funResetControls()
-
{
-
document.getElementById("name").value=""
-
document.getElementById("dob").value=""
-
document.getElementById("address").value=""
-
document.getElementById("Male").checked=false
-
document.getElementById("Female").checked=false
-
document.getElementById("degree").value="BE"
-
document.getElementById("btnInsert").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)end if%>" style="width: 296px" /></td><br />
-
</tr>
-
<tr>
-
<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
-
<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 />
-
</tr>
-
<tr>
-
<td> Degree:</td><td> <select style="width: 300px" id= ddlDegree name=degree>
-
<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>
-
<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>
-
<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>
-
<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>
-
<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>
-
</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").value)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="funResetControls()" style="width: 103px"/>
-
<input type=submit name=button id=btnInsert value="Insert" onclick="return validate()" style="width: 103px" disabled="disabled" /></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.MoveNext
-
m_nTotNoOfRecords=m_nTotNoOfRecords+1
-
Response.Write("<br><br>")
-
-
loop
-
session("nTotNoOfRecords")= m_nTotNoOfRecords
-
m_rsInfo.Close
-
m_connADOASP.Close
-
-
%>
-
<%
-
-
if (request.Form("button")="Insert") then
-
-
set m_connADOASP = server.createobject("adodb.connection")
-
m_connADOASP.Open "driver={sql server}; server=rahul\sqlexpress; database=ADOASP; uid=sa; 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_connADOASP.Execute m_sQuery
-
m_connADOASP.close
-
Response.redirect("Move.asp")
-
-
end if
-
-
%>
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. - 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
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
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
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. - 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
hi Jared
can you please help in this regard also
http://www.thescripts.com/forum/thread743115.html
i have posted this before.
thank .
Rahul
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: - 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 - 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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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)
|
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)....
|
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...
|
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?
|
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...
|
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.
...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |