Form 放在ascx中或masterpage中__dopostback解决报错的问题!

来源:互联网 发布:linq 找出重复数据 编辑:程序博客网 时间:2024/04/29 17:08

 

asp.net 1.1 版本里有一个BUG都知道

 

 

如果你把Form放在ascx里面而且有__doPostBack调用的话肯定会是下面这样地:

<!--
function __dopostback(eventtarget, eventargument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
   theform = document.forms["_ctl0:Form1"];
  }
  else {
   theform = document._ctl0:Form1;      // 这玩意一眼都看出有错!!
  }

theform.__eventtarget.value = eventtarget.split("$").join(":");
theform.__eventargument.value = eventargument;
theform.submit();
}
// -->

 

有时候做项目,用户环境就这样,你不可能去把客户的系统重新安装过!!....会死人的!!

 

利用javascript  里面的"函数重载",    简单:

 

在<form ....>的下面手动再添加一个__doPostBack 函数:

 

<script language="javascript">
<!--
 function __doPostBack(eventTarget, eventArgument) {
  var theform;
  if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
   theform = document.forms["_ctl0:Form1"];
  }
  else {
   theform = document._ctl0_Form1;
  }
  theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
  theform.__EVENTARGUMENT.value = eventArgument;
  theform.submit();

// alert("你自己的doPostBack");
 }
// -->
</script>

 

 

安逸, 生成 HTML里面就会出现两上__doPostBack,而到的就是你的!