2010-07-21 67 views
1

當回發已經在進行時,禁止從asp.net回發一個帖子,即按鈕,鏈接,gridview頁面索引改變和排序等。目標瀏覽器是IE 6+。我寫了這兩個JavaScript我不知道如何將它應用於GridView頁面索引更改。當一個已經在進行中時禁止POST POST返回

<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> 

對於按鈕,我可以將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。

+0

所有我要說的是????? – JonH 2010-07-21 19:51:26

+0

是不是這樣,你想減少一個按鈕被按下後的二級帖子的可能性?類似這樣的: http://ddkonline.blogspot.com/2008/02/aspnet-double-postback-bug-strikes.html – Irwin 2010-07-21 19:54:22

+0

不禁用回發我需要禁止其他回發帖子時回發仍在進行中。我有一個網頁,它執行從Excel文件到CRM系統的大約10萬條記錄的批量導入。我在網格上顯示記錄,然後當用戶按下進程時,我將處理服務器上的記錄,最後在同一個網格上顯示結果。但在處理過程中,我不希望用戶點擊say鏈接(即GridView PageIndex或任何其他按鈕)。所以基本上我希望用戶在一個回發完成之前等待。 – 2010-07-21 20:05:06

回答

2
onclick="this.disabled=true;" 
您提交按鈕(一個或多個)

是所有的JavaScript「神奇」你需要

jQuery是你可以使用這個小腳本禁用所有提交-按鈕選項:

// Find ALL <form> tags on your page 
$('form').submit(function(){ 
    // On submit disable its submit button 
    $('input[type=submit]', this).attr('disabled', 'disabled'); 
}); 

這裏找到:http://jquery-howto.blogspot.com/2009/05/disable-submit-button-on-form-submit.html

或者,您可以阻止整個頁面:http://jquery.malsup.com/block/#page

+1

這將禁用當前控件,但用戶仍可以從其他控件或鏈接回發,例如單擊GridView PageIndex。 – 2010-07-21 20:01:13

+0

更新了我的答案 – 2010-07-21 20:10:57

1

如果您想要禁用回發集autopastback=false的按鈕鏈接。 否則,您需要提供更多信息和更好的說明/細節來幫助您。

1

我會猜測你在這裏做的是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; 
    } 
+0

好吧,但如何做爲傳呼機的GridView ..我需要禁用GridView和所有鏈接...即在列名鏈接排序和爲GridView顯示的PagerIndexes ...得到了我的觀點? – 2010-07-21 20:09:41

0

,我發現最簡單的解決方案是..

//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>