按钮更新面板内不会被触发,在asp.net [英] Button inside Update Panel is not triggered, in asp.net

查看:261
本文介绍了按钮更新面板内不会被触发,在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>

Add按钮有一个事件的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 属性 。这将导致由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.

修改:刚刚意识到 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>

编辑#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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆