如何检查页面刷新和页面提交? [英] how to check for page refresh and page submit?

查看:91
本文介绍了如何检查页面刷新和页面提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



可以帮助我这方面

我从我的asp页面输入数据库中的一些值。为此,我使用提交按钮将表单提交到insert.asp的新页面。此页面执行插入并将其重定向回我的previos页面。

我可以不在同一页面上插入这个吗?

如果我在同一页面上插入代码,它也会执行页面刷新的插入...这就是为什么我使用另一个页面(有些人说为什么用户刷新页面?..但我们不能restrick用户不要刷新页面......)....

所以有什么方法可以在提交点击时执行插入而不是在页面刷新...

或有没有办法在两个不同的按钮上调用两个不同的服务器端功能(或执行两个不同的代码)。


请帮助......

thnx提前..


Rahul


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

推荐答案

嗨Rahul,


因此,如果我已经评估了您正确要求的内容,那么您将在表格中输入值,然后将这些值发送到页面insert.asp。并且一旦插入,您将用户重定向回输入页面(例如,input.asp)?


如果您可以提供示例代码 ; input.asp"和insert.asp然后我可以引导您完成它并向您展示如何将数据提交到同一个ASP页面,处理它并进行重定向,所有这些都在一个页面中。


如果你能'不提供您的示例代码,我只能建议您 - 在input.asp中使用表单中的隐藏输入。并将数据提交给input.asp - 然后,您可以使用一些简单的错误和值检查来检查用户是否已刷新,然后再次加载input.asp。


祝你好运,


medicineworker
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


这是我的插入内容。 asp


< html>

< head>

< title>显示在同一页面上< / title>

< / head>

< body>

< form>


< / form>


<%


set Conn = server.createobject(" adodb.connection")

Conn.Open" driver = {sql服务器};服务器= SERVERNAME;数据库=数据库; UID = UID; PWD = PASSWORD;"


sql =" INSERT TABLE info VALUES"

sql = sql& "(''"& Request.Form(" Name")&"'',"

sql = sql&"''"& Request。表格(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>


这是我的第一页ASPAssignmentasp



< html>

< head >

< title>显示在同一页上< / title>


< script language = javascript>


函数DateExists(值)

{

d =新日期()

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

var date = value.substring(value.indexOf(" /& quot;)+ 1,value.lastIndexOf( " /"));

var month = value.substring(0,value.indexOf(" /"));


if (月== 4 ||月== 6 ||月== 9 ||月== 11)

{

if(date> 30){return假; }

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; }

}



}


函数验证( )

{


var str =""

if(document.getElementById(" txtName")。value =="")

{

str + ="名称不能为空\ n"

}

if(document.getElementById(" txtDOB")。value =="")

{

str + ="请输入出生日期\ n"

}

其他

{

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})
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(" txtDOB")。value)!= true)

{

str + ="请输入正确的值in日期字段\\ n+日期必须采用格式MM / DD / YYYY \ n"

}

}


if(DateExists(document.getElementById(" txtDOB")。valu e)== false)

{

str + ="输入日期作为出生日期不存在\ n"

}


if(document.getElementById(" Male")。checked == false&& document.getElementById(" Female")。checked == false)

{

str + ="请选择性别\ n"

}


value = document.getElementById(" txtDOB")。value

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


if(d.getFullYear()< parseInt(year)+ parseInt(18))

{

str + ="年龄必须大于18年\ n"

}

if(document.getElementById(" txtAddress")。value = ="")

{

str + ="地址不能为空\ n \\ n"

}


if(str!="")

{

alert("请更正以下内容:\ nn \\ n" + str)

// window.location.reload();

返回false

}


}



< / script>


<%

set Conn = server.createobject(" adodb.connection")

Conn 。打开driver = {sql server}; server = SERVER NAME;数据库=数据库; UID = UID; PWD = PASSWORD;"


set rs = Server.CreateObject(" ADODB.recordset")

rs.Open" Select * from TABLE",conn

response.Write("< P>")


%>


<%



如果(rs.EOF<> true)那么


选择案例(rs("度"))


case" BE"

BE =选择

case" B.TECH"

BTECH =选择

案例MCA

MCA =选择

案例MBA

MBA =" selected"

case" M.TECH"

MTECH =" selected"


结束选择




选择案例(rs(" gender"))

案例" ;男性

m ="选中"

case" Femal e"

f =" check"

结束选择


结束如果


%>


< / head>


< body style =" font-family:Verdana; font-size:较小的">




< form id =" form1" method = get action =" ASPAssignment2.asp" >

< br />

< table style =" font-family:Verdana; font-size:10pt">

< tr>

< td align =" right" >姓名:< / td>

< td><输入类型=文字ID = txtName名称=名称值="<%if(rs.EOF<> true)然后回复.Write(rs(" Name")))if 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)然后response.Write(rs(dob))end if if>" style =" width:300px" />< / td>

< / tr>

< tr>

< td align =" right" >性别:< / td>

< td><输入类型=无线电值=男性<%= m%> id =男性姓名=性别风格="宽度:25px" />男& nbsp; &安培; NBSP; & nbsp;

< input type = radio value = Female<%= f%> id =女性姓名=性别风格="宽度:25px" />女< / td>

< / tr>

< tr>

< td align =" right">资格:< / 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">地址:< / td>

< td><输入type = text id = txtAddress name = address value ="<%if(rs.EOF<> true)则response.Write(rs(" address"))if 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>


<%




,而不是rs.EOF
每个x在rs.fields中的


response.write(x .name)

response.write(" =")

response.write(x.value)

response.Write(" ;< br>")


next


rs.MoveNext

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

循环

conn.Close


%>


< / body>

< / html>
/;

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>


这篇关于如何检查页面刷新和页面提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆