给出一个Ajax Control Toolkit手风琴:
<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>
单击该按钮时,模式消息框将按预期显示“请确认”。
当用户将其解雇时,手风琴认为已被点击并关闭了活动面板,这是不可取的。
有什么方法可以抑制这种行为吗?
答案 0 :(得分: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);
}