• ASP.Net 1.x 中 __doPostBack实现的问题


    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

  • 相关阅读:
    LeetCode 3.将整数中每位上的数字进行反转
    LeetCode 2. 将两个链表一一对应的各个结点的值相加并逆序输出
    79.单词搜索
    Java内存区域
    46. 全排列
    17. 电话号码的字母组合
    93. 复原IP地址
    40. 组合总和 II
    39. 组合总和
    59.螺旋矩阵二
  • 原文地址:https://www.cnblogs.com/ruanbl/p/776820.html
Copyright © 2020-2023  润新知