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

posted on 2007-06-08 17:09  MainIsUsed  阅读(255)  评论(0编辑  收藏  举报