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);
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18