闲话少说,将以下脚本放置于页面顶部.

document.IsPosted
=
false
;
2

function
CancelDubSubmit()
3



{
4
if ((typeof(event.returnValue) == “undefined“ || event.returnValue== true) && !document.IsPosted)5

{ 6
document.IsPosted = true;7
event.returnValue = true;8
}9
else10

{ 11
event.returnValue = false;12
}13
}
以下加粗部分放置于form标签中,如果你已经有了onsubmit事件的其他执行函数,可以放在一起,最好将CancelDubSubmit()函数放在最后.

<
form
id
=”Form1″
onsubmit
=”CancelDubSubmit();”
method
=”post”
runat
=”server”
>
其中document.IsPosted是为了记录是否回送.一旦页面回送,document.IsPosted将为true. 重新加载后,document.IsPosted=false将被执行.当onsubmit事件没有其他执行函数或者其他执行函数返回true并且document.IsPosted=false时,回送页面,否则停止回送.
以上方法不能控制使用 function __doPostBack() 函数的服务器端控件.因为在此函数中的提交是靠 document.Form1.submit() 实现的,它不会触发Onsubmit事件.那么我们还需要重写__doPostBack() 函数.


function
__doPostBack(eventTarget, eventArgument)

{
if (!document.IsPosted)
{
var theform;
if (window.navigator.appName.toLowerCase().indexOf(“netscape“) > –1)
{
theform = document.forms[“Form1“];
}
else
{
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split(“$“).join(“:“);
theform.__EVENTARGUMENT.value = eventArgument;
document.IsPosted = true;
theform.submit();
}
}
请将以上代码放置于页面的原__doPostBack() 函数之后.
转载于:https://www.cnblogs.com/redfire0922/archive/2006/06/20/430746.html
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/111143.html原文链接:https://javaforall.net
