在 asp.net 中,未触发更新面板内的按钮 [英] Button inside Update Panel is not triggered, in asp.net
问题描述
<asp:ModalPopupExtender ID="MPE_EditGroup" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup" CancelControlID="btnCancel" />
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Panel ID="pnlpopup" runat="server">
<asp:ListBox ID="lst_allmembers" DataValueField="FirstName" runat="server" />
<asp:Button ID="btn_Add" runat="server" Text="Add" OnClick="btn_Add_Click" /><asp:ListBox ID="lst_grpmembers" runat="server" />
<asp:Button ID="btn_remove" runat="server" Text="Remove" />
<asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" /></asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
添加按钮有一个事件 OnClick="btn_Add_Click"
The add button has a event OnClick="btn_Add_Click"
protected void btn_Add_Click(object sender, EventArgs e)
{
lst_grpmembers.Items.Add(lst_allmembers.SelectedItem.Text);
}
未触发事件,当我单击添加按钮时,没有任何反应.在我添加更新面板之前,更新按钮工作正常,现在只有取消按钮关闭弹出窗口,弹出窗口内没有其他按钮工作如何触发事件.
The event is not triggered and when I click the add button nothing happens. And the Update Button was working fine before I added the update panel now only the cancel button closes the popup no other button works inside the pop up How to trigger the event.
推荐答案
将 UpdatePanel 的 ChildrenAsTriggers
属性更改为 true
.这将导致由 UpdatePanel 的子元素触发的任何回发更新其内容.
Change the UpdatePanel's ChildrenAsTriggers
property to true
. This will cause any postbacks triggered by the UpdatePanel's child elements to update its content.
EDIT:刚刚意识到btn_Add
是一个嵌套控件,因此您必须将其显式调用为UpdatePanel 触发器
.将以下内容添加到您的 UpdatePanel 标记中,在 ContentTemplate 之后:
EDIT: Just realized that btn_Add
is a nested control, so you will have to explicitly call it out as an UpdatePanel Trigger
. Add the following to your UpdatePanel markup, after the ContentTemplate:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn_Add" />
</Triggers>
EDIT #2:为了防止在发生异步回发时关闭模态弹出窗口,请将 UpdatePanel
移动到由 ModalPopupExtender 的 PopupControlID 指定的面板内:
EDIT #2: To keep your modal popup from closing when an async postback occurs, move the UpdatePanel
inside the panel specified by ModalPopupExtender's PopupControlID:
<asp:Panel ID="pnlpopup" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:ListBox ID="lst_allmembers" DataValueField="FirstName" runat="server" />
<asp:Button ID="btn_Add" runat="server" Text="Add" OnClick="btn_Add_Click" />
<asp:ListBox ID="lst_grpmembers" runat="server" />
<asp:Button ID="btn_remove" runat="server" Text="Remove" />
<asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
这篇关于在 asp.net 中,未触发更新面板内的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!