在 asp.net 中,更新面板内的按钮未触发

发布于 12-08 15:52 字数 1362 浏览 1 评论 0原文

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲2024-12-15 15:52:35

将 UpdatePanel 的 ChildrenAsTriggers 属性更改为 true。这将导致由 UpdatePanel 的子元素触发的任何回发来更新其内容。

编辑:刚刚意识到btn_Add是一个嵌套控件,因此您必须将其显式调用为UpdatePanel触发器。将以下内容添加到 UpdatePanel 标记中的 ContentTemplate 之后:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btn_Add" /> 
</Triggers>

编辑#2:要防止模态弹出窗口在异步回发发生时关闭,请将 UpdatePanel 移动到指定的面板内通过 ModalPopupExtender 的 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>

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: 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: 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文