在 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"
protected void btn_Add_Click(object sender, EventArgs e)
{
lst_grpmembers.Items.Add(lst_allmembers.SelectedItem.Text);
}
该事件未触发,当我单击添加按钮时没有任何反应。在我添加更新面板之前,更新按钮工作正常,现在只有取消按钮关闭弹出窗口,弹出窗口内没有其他按钮工作 如何触发事件。
<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>
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 的子元素触发的任何回发来更新其内容。编辑:刚刚意识到
btn_Add
是一个嵌套控件,因此您必须将其显式调用为UpdatePanel触发器
。将以下内容添加到 UpdatePanel 标记中的 ContentTemplate 之后:编辑#2:要防止模态弹出窗口在异步回发发生时关闭,请将
UpdatePanel
移动到指定的面板内通过 ModalPopupExtender 的 PopupControlID:Change the UpdatePanel's
ChildrenAsTriggers
property totrue
. This will cause any postbacks triggered by the UpdatePanel's child elements to update its content.EDIT: Just realized that
btn_Add
is a nested control, so you will have to explicitly call it out as anUpdatePanel Trigger
. Add the following to your UpdatePanel markup, after the ContentTemplate: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: