ASP.Net 1.x的client side postback script是這樣的:
<!--
function __doPostBack(eventTarget, eventArgument) {
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;
theform.submit();
}
// -->
它
是通過form.submit()去submit的。這樣就有一個問題,form.onsubmit事件不會被觸發,這麼一來可能有些client
side validation script就被繞過了。在ASP.Net 2.0裡,這個問題被fix了。對於ASP.Net
1.x,據我所知,SP1也沒有解決這個問題。我們可以使用下面的代碼解決這個問題:
string myDoPostBack = @"
<script language=""javascript"">
<!--
function __myDoPostBack(eventTarget, eventArgument) {
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;
if ((typeof(theform.onsubmit) == ""function"") && theform.onsubmit()!=false) {
theform.submit();
}
}
__doPostBack = __myDoPostBack
// -->
</script>";
RegisterStartupScript("myDoPostBack", myDoPostBack);
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=194208