2012-03-23 33 views
1

鑑於一個Ajax控制工具包手風琴在手風琴報頭中的控制:防止從觸發手風琴滾上/下行爲

<ajaxToolkit:Accordion runat="server" 
    SelectedIndex="0" 
    HeaderCssClass="accordionHeader" 
    HeaderSelectedCssClass="accordionHeaderSelected" 
    ContentCssClass="accordionContent" 
    AutoSize="None" 
    FadeTransitions="true" 
    TransitionDuration="250" 
    FramesPerSecond="40" 
    RequireOpenedPane="false" 
    SuppressHeaderPostbacks="true"> 

與在HeaderTemplate中一個ConfirmButtonExtender成對的按鈕:

<HeaderTemplate> 
     <asp:Button 
      ID="PushPlanButton" 
      Text="Push" 
      runat="server" 
      OnClick="PushPlanButtonPressed" /> 

     <ajaxToolkit:ConfirmButtonExtender 
      ID="ConfirmButtonExtender1" 
      runat="server" 
      TargetControlID="PushPlanButton" 
      ConfirmText="Please confirm" /> 
    </HeaderTemplate> 

當點擊按鈕時,模態消息框出現,「請確認」,如預期的那樣。

當用戶解散它時,Accordion認爲它已被點擊並關閉活動面板,這是不期望的。

任何方法來抑制這種行爲?

回答

1

我認爲最好的選擇是根據你的需要調整AjaxControlToolkit源代碼。在這種情況下,您只需在confirmButtonBehavior.pre.js文件中進行位更改。改寫如下_onClick方法:

_onClick: function (e) { 
    /// <summary> 
    /// Button's click handler to display the confirmation dialog 
    /// </summary> 
    /// <param name="e" type="Sys.UI.DomEvent"> 
    /// Event info 
    /// </param> 

    if (this.get_element() && !this.get_element().disabled) { 
     if (this._ConfirmOnFormSubmit) { 
      // Note that this behavior was triggered (for later) 
      Sys.Extended.UI.ConfirmButtonBehavior._clickedBehavior = this; 
     } else { 
      // Display the dialog and cancel the click if necessary 
      if (!this._displayConfirmDialog()) { 
       e.preventDefault(); 
       e.stopPropagation(); // added to prevent event bubbling 
       return false; 
      } 
      else if (this._oldScript) { 

       if (String.isInstanceOfType(this._oldScript)) { 
        eval(this._oldScript); 
       } 
       else if (typeof (this._oldScript) == 'function') { 
        this._oldScript(); 
       } 
      } 
     } 
    } 
} 

但是,如果你不能被一些調整的原因庫源代碼,你可以申請另一種方法。將以下腳本添加到頁面上:

function pageLoad() 
{ 
    var extender = $find("<%= ConfirmButtonExtender1.ClientID %>"); 
    $removeHandler(extender.get_element(), "click", extender._clickHandler); 

    extender._clickHandler = Function.createDelegate(extender, function (e) { 
      if (this.get_element() && !this.get_element().disabled) { 
       if (this._ConfirmOnFormSubmit) { 
        // Note that this behavior was triggered (for later) 
        Sys.Extended.UI.ConfirmButtonBehavior._clickedBehavior = this; 
       } else { 
        // Display the dialog and cancel the click if necessary 
        if (!this._displayConfirmDialog()) { 
         e.preventDefault(); 
         e.stopPropagation(); 
         return false; 
        } 
        else if (this._oldScript) { 

         if (String.isInstanceOfType(this._oldScript)) { 
           eval(this._oldScript); 
         } 
         else if (typeof (this._oldScript) == 'function') { 
           this._oldScript(); 
         } 
        } 
       } 
      } 
    }); 
    $addHandler(extender.get_element(), "click", extender._clickHandler); 
} 
+0

您是先生,是天才。我還沒有嘗試過,但顯然已經進行了研究。我會盡快嘗試並回傳。非常感謝! – tomfanning 2012-03-25 13:42:44