模态弹出控件未触发原始按钮单击事件

时间:2014-02-16 23:31:31

标签: c# asp.net ajax

也许我不理解它是如何完全工作的,但我所拥有的是一个带有imagebutton和modalpopup的gridview自定义模板。在我的页面下方,我的弹出式面板是隐藏的。当我单击我的图像按钮时,面板显示然后我单击“btnModalCancelAll”并开始逐步执​​行我的方法,该方法将页面变量设置为0到1,但问题是它没有继续到原始gridview图像点击事件不知道为什么。下面是我的模板字段和弹出式面板。

<asp:TemplateField>
                    <ItemTemplate>
                      <asp:ImageButton ID="ImageButtonCancelResv" runat="server" Width="20" Height="20px" ImageUrl="~/Images/Delete.png"  OnClick="ImageButtonCancelResv_Click" />
                          <asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="ImageButtonCancelResv" PopupControlID="pnlModalPanel" CancelControlID="btnModalCancel"></asp:ModalPopupExtender> 
                        <br />
                        <asp:Label ID="Label1" runat="server" Text="Cancel"></asp:Label>

                 </ItemTemplate>

 <asp:Panel ID="pnlModalPanel" CssClass="modalBackground" runat="server" Style="display:none">
    <asp:UpdatePanel runat="server" ID="updatePanelPopUp">
    <ContentTemplate>

            <div id="modalWrap">
             <asp:Label ID="lblAreyousure" runat="server" Text="Are you sure you want to do that?"></asp:Label>
             <div id="divhr1" class="horizontalRule" runat="server"></div>
            <div id="divCancelSummaryAll">
                   <asp:Label ID="lblEntireFamily" runat="server" Text="Cancel all family reservations from this event date."></asp:Label><br />
                   <asp:Label ID="lblSummaryDeleteAll" runat="server" Text=""></asp:Label><br />
                 <asp:Button ID="btnModalDeleteAll" runat="server" CssClass="modalButton" Text="Cancel all Family" OnClick="btnModalDeleteAll_Click" />
            </div>
            <div id="divCancelSummaryOne">
                  <asp:Label ID="Label2" runat="server" Text="Cancel selected child reservation from this event date."></asp:Label><br />
                 <asp:Label ID="lblSummaryDeleteOne" runat="server" Text=""></asp:Label><br />
                 <asp:Button ID="btnModalDeleteOne" runat="server" CssClass="modalButton" Text="Cancel this Child" OnClick="btnModalDeleteOne_Click" />
            </div>
         <br />

            <asp:Button ID="btnModalCancel" runat="server" Text="Cancel" />
           </div>
    </ContentTemplate>
</asp:UpdatePanel>
    </asp:Panel>

1 个答案:

答案 0 :(得分:0)

我建议您创建另一个按钮并将其用作模式弹出窗口的TargetControlID。 您可以通过将其显示设置为“无”来隐藏此按钮。这只是一个虚拟按钮,以便您的代码编译。

现在当您点击按钮"ImageButtonCancelResv"时,它将运行方法OnClick="ImageButtonCancelResv_Click"中的代码 在此方法结束时,您可以添加一个命令来显示弹出窗口:

mpe.Show();

示例代码:

protected void ImageButtonCancelResv_Click(object sender, EventArgs e)
{
            //Do something here when button is clicked

             mpe.Show();
}

然后

  <asp:TemplateField>
        <ItemTemplate>
          <asp:ImageButton ID="ImageButtonCancelResv" runat="server" Width="20" Height="20px" ImageUrl="~/Images/Delete.png"  OnClick="ImageButtonCancelResv_Click" />
   <div style="display: none">
        <asp:Button ID="btnModalStatusHidden" runat="server" />
    </div>
    <asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnModalStatusHidden" PopupControlID="pnlModalPanel" CancelControlID="btnModalCancel"></asp:ModalPopupExtender> 
<br />
  <asp:Label ID="Label1" runat="server" Text="Cancel"></asp:Label>
</ItemTemplate>