两个ModalPopupExtender以相同的方式使用,只有一个工作

时间:2011-04-19 15:41:54

标签: c# asp.net modalpopupextender

在gridview中,我有一个“电子邮件”按钮和一个“删除”按钮,可以使用modalpopupextender打开一个Modal弹出窗口。问题是单击按钮时会打开“电子邮件”窗口,但单击其按钮时“删除”窗口不会打开。我以同样的方式使用两个modalpopupextenders。

 <asp:ButtonField ButtonType="Button" CommandName="Email" Text="Email" />
                    <asp:ButtonField ButtonType="Button"  CommandName="Delete" Text="Delete" />

<%-- Email modal--%>      
    <asp:Panel ID="pnlPopupEmail" runat="server" Width="500px" Style="display: none">
    <asp:UpdatePanel ID="updPnlEmail" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
     <asp:Button ID="btnShowEmail" runat="server" Style="display: none" />
                <ajaxToolkit:ModalPopupExtender ID="mdlPopupEmail" runat="server" TargetControlID="btnShowEmail"
                    PopupControlID="pnlPopupEmail" CancelControlID="btnCancel" BackgroundCssClass="modalBackground" />
        <div class="EmailPopup">
            <table>
                <tr>
                    <td>
                        To:
                    </td>
                    <td>
                       <asp:TextBox ID="EmailTo" runat="server" Width="350"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        From:
                    </td>
                    <td>
                        <asp:TextBox ID="EmailFrom"  runat="server" Width="350"></asp:TextBox>
                    </td>
                </tr>
                 <tr>
                    <td>
                        Subject:
                    </td>
                    <td>
                        <asp:TextBox ID="Subject" runat="server" Width="350"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td></td>
                       <td> <asp:TextBox ID="EmailMessageBox" Width="350" Height="150" runat="server" TextMode="MultiLine" Wrap="true"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <asp:LinkButton ID="SendBtn" runat="server" OnClick="SendBtn_Clicked" Text="Send" />
                        <asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" />
                    </td>
                    <td>
                        <asp:Label ID="theID" runat="server" Visible="false"></asp:Label>
                    </td>
                </tr>
                </table>
        </div>

    </ContentTemplate>
    </asp:UpdatePanel>
    </asp:Panel>
   <%-- -----end email modal--%>
    <%-- Start Delete Confirmation Modal --%>
    <asp:Panel ID="DelConfirmPanel" runat="server" Width="500px" Style="display: none">
        <asp:UpdatePanel ID="DelConfirmUpdatePanel" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
            <asp:Label ID ="TESTLabel" runat="server" Text="Are you sure?" ></asp:Label>
                <asp:Button ID="DelModalButton" runat="server" Style="display: none" />
                <ajaxToolkit:ModalPopupExtender ID="modalPopUpDelConfirm" runat="server" TargetControlID="DelModalButton"
                    PopupControlID="DelConfirmPanel" CancelControlID="DeleteCancel" BackgroundCssClass="modalBackground" />
                <div class="DeletePopup">
                    <asp:LinkButton ID="DelConfirmedButton" runat="server" OnClick="DeleteConfirmation_Clicked"
                        Text="Delete" />
                    <asp:LinkButton ID="DeleteCancel" runat="server" Text="Cancel" CausesValidation="false" />
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Panel>
    <%-- End Delete Confirmation Modal --%>
</div>

然后在代码隐藏中,我有一个方法来检查命令名称并更新updatepanel并显示modalpopupextender。

protected void btn_Clicked(object sender, GridViewCommandEventArgs e)
{

    if (e.CommandName == "Email")
    {
        // a bunch of stuff that I am leaving out but is just changing fields in the
        //table withing the modal popup
        updPnlEmail.Update();
        mdlPopupEmail.show();
    }

    if (e.CommandName.Equals("Delete"))
    {
        int index = Convert.ToInt32(e.CommandArgument);
        String id = gvReservations.DataKeys[index].Value.ToString();    // get id
        try
        {
            DelConfirmUpdatePanel.Update();
            modalPopUpDelConfirm.Show();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }
}

任何想法为什么一个有效而不是另一个?有没有一种好方法来调试这种错误?非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

想出来。

<asp:ButtonField ButtonType="Button"  CommandName="Delete" Text="Delete" />

这就是问题所在。我没有意识到“删除”是一个保留的命令名称。因此,当单击此按钮时,会抛出异常,说它无法从表中删除。因此,模态弹出窗口从未显示过。我通过在chrome工具中打开javascript控制台来解决这个问题。

所以要修复它,我将命令名改为其他东西,现在一切都按预期工作了。