Javascript 禁止已在进行中的回发

Javascript 禁止已在进行中的回发,javascript,asp.net,internet-explorer,Javascript,Asp.net,Internet Explorer,当回发已在进行时,禁用asp.net的回发,即按钮、链接、gridview页面索引更改和排序等。目标浏览器是IE6+。我已经编写了这两个javascript,我不知道如何将其应用于GridView页面索引更改 <script type="text/javascript"> //isFormSubmitted variable is used to prevent the form submission while the server execution is i

当回发已在进行时,禁用asp.net的回发,即按钮、链接、gridview页面索引更改和排序等。目标浏览器是IE6+。我已经编写了这两个javascript,我不知道如何将其应用于GridView页面索引更改

<script type="text/javascript">
          //isFormSubmitted variable is used to prevent the form submission while the server execution is in progress
          var isFormSubmitted = false;
          //If the form is already submitted, this function will return false preventing the form submission again.
          function SubmitForm(msg)
          {
            try {
             if(isFormSubmitted == true)
             {
               alert('A post back is already in progress. Please wait');
               return false; 
             }
             else 
             {
               var res = false;
               if (msg)
               {
                 res = confirm(msg);
               }
               if (res == true)
               {  
                 isFormSubmitted = true;
               }
               return res;
             }
           } catch(ex) {}
          }

          function VerifySubmit()
          {
             if(isFormSubmitted == true)
             {
               alert('A post back is already in progress. Please wait');
               return false; 
             }
             else 
             {
               isFormSubmitted = true;
               return true;
             }
          } 
</script>

//isFormSubmitted变量用于在服务器执行过程中防止表单提交
var isFormSubmitted=false;
//如果表单已经提交,此函数将返回false,以防止再次提交表单。
函数提交表单(msg)
{
试一试{
如果(isFormSubmitted==true)
{
警报('回发已在进行中,请稍候');
返回false;
}
其他的
{
var-res=false;
如果(味精)
{
res=确认(msg);
}
如果(res==true)
{  
isFormSubmitted=true;
}
返回res;
}
}捕获(ex){}
}
函数VerifySubmit()
{
如果(isFormSubmitted==true)
{
警报('回发已在进行中,请稍候');
返回false;
}
其他的
{
isFormSubmitted=true;
返回true;
}
} 
对于按钮,我可以像这样将SubmitForm附加到OnClientClick

<asp:Button ID="btnCancel" runat="server" CssClass="button" Text="Cancel" OnClick="btnCancel_Click" OnClientClick="return SubmitForm('Do you want to continue with cancelling recent action?');" />


但我不知道如何将VerifySubmit附加到gridview pager等非提示控件。

如果要禁用按钮链接的回发设置
autocastback=false

否则,您需要向我们提供更多信息和更好的说明/详细信息来帮助您。

如果您想禁用按钮链接的回发设置
autocastback=false
 onclick="this.disabled=true;"
否则,您需要向我们提供更多信息和更好的说明/详细信息来帮助您

 onclick="this.disabled=true;"
在你的提交按钮上有你所需要的全部javascript“魔力”

当是一个选项时,您可以使用此小脚本禁用所有提交按钮:

// Find ALL <form> tags on your page
$('form').submit(function(){
    // On submit disable its submit button
    $('input[type=submit]', this).attr('disabled', 'disabled');
});
//查找页面上的所有标记
$('form')。提交(函数(){
//在提交时禁用其提交按钮
$('input[type=submit]',this.attr('disabled','disabled');
});
可在此处找到:

或者,您可以阻止整个页面:

在你的提交按钮上有你所需要的全部javascript“魔力”

当是一个选项时,您可以使用此小脚本禁用所有提交按钮:

// Find ALL <form> tags on your page
$('form').submit(function(){
    // On submit disable its submit button
    $('input[type=submit]', this).attr('disabled', 'disabled');
});
//查找页面上的所有标记
$('form')。提交(函数(){
//在提交时禁用其提交按钮
$('input[type=submit]',this.attr('disabled','disabled');
});
可在此处找到:


或者你可以阻止整个页面:

我猜你在这里做的是ajaxy类型的东西,你有一个异步回发,你不想让用户在那个时候点击一个按钮

如果是这种情况,请尝试以下代码:

    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(startRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);

    function startRequest(sender, e) {
        //disable search button during the AJAX call
        document.getElementById('<%=btnSearch.ClientID%>').disabled = true;

    }

    function endRequest(sender, e) {
        //re-enable the search button once the AJAX call has completed
        document.getElementById('<%=btnSearch.ClientID%>').disabled = false;
    }
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(startRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
函数startRequest(发送方,e){
//在AJAX调用期间禁用搜索按钮
document.getElementById(“”).disabled=true;
}
函数endRequest(发送方,e){
//AJAX调用完成后,重新启用搜索按钮
document.getElementById(“”).disabled=false;
}

我猜你在这里做的是ajaxy类型的东西,你有一个异步回发,你不想让用户在那个时候点击一个按钮

如果是这种情况,请尝试以下代码:

    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(startRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);

    function startRequest(sender, e) {
        //disable search button during the AJAX call
        document.getElementById('<%=btnSearch.ClientID%>').disabled = true;

    }

    function endRequest(sender, e) {
        //re-enable the search button once the AJAX call has completed
        document.getElementById('<%=btnSearch.ClientID%>').disabled = false;
    }
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(startRequest);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
函数startRequest(发送方,e){
//在AJAX调用期间禁用搜索按钮
document.getElementById(“”).disabled=true;
}
函数endRequest(发送方,e){
//AJAX调用完成后,重新启用搜索按钮
document.getElementById(“”).disabled=false;
}

我找到的最简单的解决方案是

//In the head section define this script...

    <script type="text/javascript">
      function ShowProcessingMsg(confirmMsg) {
        var resp = confrim(confirmMsg);
        try {
          if (resp == true) {
            var divC = document.getElementById('<%= divControls.ClientID %>');
            var divM = document.getElementById('<%= divProcessingMsg.ClientID %>');
            if (divC && divM) {
              divC.display = "none";
              divM.display = "block";
            }
            else {
              return false;
            }
          }
        } catch (exp) { alert(exp); return false; }
        return resp;
      }
    </script>

//This div will show during processing since by default it's display is none when after
//Post back your page loaded again this will not be diplayed. We are going to set it's
//diplay attribute to block from javascript.

<div id="divProcessingMsg" runat="server" display="none" z-index="1000" />
   <b>Processing.... Please wait.</b>
</div>


//We will hide this div from script by setting its display attribute to none. Since 
//by default this attribute is block when the page loaded again it'll be displayed by 
//default. So no special handling for setting display again to block is required.

<div id="divControls" runat="server" display="block" z-index="1" />
   <asp:GridView ............ >
   .....
   .....
   .....
   <asp:Button runat="server" id="btnProcess" Text="Process" OnClientClick="return ShowProcessingMsg('Do you want to continue with processing'); OnClick="btnProcess_ServerClick" />
</div>
//在head部分定义此脚本。。。
函数ShowProcessingMsg(confirmMsg){
var resp=确认(确认消息);
试一试{
如果(resp==true){
var divC=document.getElementById(“”);
var divM=document.getElementById(“”);
if(divC&&divM){
divC.display=“无”;
divM.display=“块”;
}
否则{
返回false;
}
}
}catch(exp){alert(exp);返回false;}
返回响应;
}
//此div将在处理过程中显示,因为默认情况下,在处理之后显示为none
//回发你的页面再次加载,这将不会显示。我们将把它设置为
//diplay属性从javascript中阻止。
处理。。。。请稍等。
//我们将通过将这个div的display属性设置为none来隐藏它。自从
//默认情况下,当再次加载页面时,此属性为block,它将由
//默认。因此,无需对再次将显示设置为块进行特殊处理。
.....
.....
.....

我找到的最简单的解决办法是

//In the head section define this script...

    <script type="text/javascript">
      function ShowProcessingMsg(confirmMsg) {
        var resp = confrim(confirmMsg);
        try {
          if (resp == true) {
            var divC = document.getElementById('<%= divControls.ClientID %>');
            var divM = document.getElementById('<%= divProcessingMsg.ClientID %>');
            if (divC && divM) {
              divC.display = "none";
              divM.display = "block";
            }
            else {
              return false;
            }
          }
        } catch (exp) { alert(exp); return false; }
        return resp;
      }
    </script>

//This div will show during processing since by default it's display is none when after
//Post back your page loaded again this will not be diplayed. We are going to set it's
//diplay attribute to block from javascript.

<div id="divProcessingMsg" runat="server" display="none" z-index="1000" />
   <b>Processing.... Please wait.</b>
</div>


//We will hide this div from script by setting its display attribute to none. Since 
//by default this attribute is block when the page loaded again it'll be displayed by 
//default. So no special handling for setting display again to block is required.

<div id="divControls" runat="server" display="block" z-index="1" />
   <asp:GridView ............ >
   .....
   .....
   .....
   <asp:Button runat="server" id="btnProcess" Text="Process" OnClientClick="return ShowProcessingMsg('Do you want to continue with processing'); OnClick="btnProcess_ServerClick" />
</div>
//在head部分定义此脚本。。。
函数ShowProcessingMsg(confirmMsg){
var resp=确认(确认消息);
试一试{
如果(resp==true){
var divC=document.getElementById(“”);
var divM=document.getElementById(“”);
if(divC&&divM){
divC.display=“无”;
divM.display=“块”;
}
否则{