模态弹出框内的两个占位符

本文关键字:两个 占位符 模态 | 更新日期: 2023-09-27 18:12:07

我有一个模态弹出式扩展器。在面板中我有两个占位符。两者都是明显错误的。当我按下一个按钮,代码就像this.ModalPopupExtender1.Show(); PlaceHolder1.Visible = true; PlaceHolder2.Visible = false;模态弹出窗口打开。当我有这样的代码:

this.ModalPopupExtender1.Show();
        PlaceHolder1.Visible = false;
        PlaceHolder2.Visible = true;

模式弹出框没有打开。如何解决这个问题?我附上我的asp.net代码:

<asp:Button  ID="btnShowPopup" runat="server" style="display:none" /> 
  <asp:ModalPopupExtender 
    ID="ModalPopupExtender1" runat="server" PopupControlID="pnlpopup" 
    TargetControlID="btnShowPopup" CancelControlID="btnCancel" 
    OkControlID="btnUpdate"     BehaviorID="ModalPopupExtender1"   DropShadow="true"   
    BackgroundCssClass="modalBackground">
  </asp:ModalPopupExtender>
    <asp:Panel ID="pnlpopup" runat="server" BackColor="LightGray"  
         CssClass="modalPopup" Width="600px" Height="450px">
          <asp:PlaceHolder ID="PlaceHolder1" Visible="false" runat="server">

                      <table class="style1">
                          <tr>
                              <td>
                                  &nbsp;</td>
                              <td>
                                  &nbsp;</td>
                          </tr>
                          <tr>
                              <td>
                                   Name:</td>
                              <td>
                                  <asp:TextBox ID="txtName" runat="server" CssClass="textEntry"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtThoughtName" ErrorMessage="*" ValidationGroup="r"></asp:RequiredFieldValidator>
                        </td>
                          </tr>
                          <tr>
                              <td>
                                  Description:</td>
                              <td>
                                   <asp:TextBox ID="txtDescription" TextMode="MultiLine" Columns="37" 
                            Rows="5" runat="server" CssClass="textEntry"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="txtDescription" ValidationGroup="r"></asp:RequiredFieldValidator>
                        </td>
                          </tr>
                          <tr>
                              <td>
                                   Date:</td>
                              <td>
                                   <asp:TextBox ID="txtDate" runat="server" Width="150px"></asp:TextBox>
                        <asp:CalendarExtender
                            ID="CalendarExtender1" runat="server" TargetControlID="txtDate">
                        </asp:CalendarExtender><asp:RequiredFieldValidator ID="RequiredFieldValidator4" 
                            runat="server" ErrorMessage="*" ControlToValidate="txtDate" 
                            ValidationGroup="r"></asp:RequiredFieldValidator>
                        </td>
                          </tr>
                              <td>
                                  &nbsp;</td>
                              <td>
                                  &nbsp;</td>
                          </tr>
                          <tr>
                              <td colspan="2">
                                 <asp:Button ID="btnUpdate" runat="server" CommandName="Update" 
                          OnClick="btnUpdate_Click" Text="Create" ValidationGroup="r" Width="100px" />&nbsp;&nbsp;
                      <asp:Button ID="btnCancel" runat="server" onclick="btnCancel_Click" 
                          Text="Cancel" Width="100px" /></td>
                          </tr>
                      </table>
                      </asp:PlaceHolder>
                 <asp:PlaceHolder ID="PlaceHolder2" Visible="false" runat="server">
                 <table class="style1">
                          <tr>
                              <td class="style6">
                                  Join a Group:</td>
                              <td>
                                  <asp:DropDownList ID="DropDownList1" runat="server" 
                                      DataSourceID="SqlDataSource3" DataTextField="GroupName" 
                                      DataValueField="GroupId">
                                  </asp:DropDownList>
                                  &nbsp;
                                  <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Create a Group</asp:LinkButton>
                              </td>
                          </tr>
                          <tr>
                              <td class="style6">
                                  &nbsp;</td>
                              <td>
                                  <asp:Button ID="btnUpdate3" runat="server" CommandName="Update" 
                                    Width="160px"  OnClick="btnUpdate2_Click" Text="Join Group" ValidationGroup="a" />
                                  &nbsp;
                                  <asp:Button ID="btnCancel3" runat="server" onclick="btnCancel2_Click" 
                                    Width="160px"  Text="Cancel" />
                              </td>
                          </tr>
                          <tr>
                              <td class="style6">
                                  <asp:Label ID="Label3" Visible="false" runat="server" Text="Group Name:"></asp:Label>
                              </td>
                              <td>
                                  <asp:TextBox ID="txtgroupname" Visible="false" CssClass="textEntry" runat="server"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="txtgroupname" ValidationGroup="z" runat="server" ErrorMessage="*"></asp:RequiredFieldValidator>
                              </td>
                          </tr>
                          <tr>
                              <td class="style6">
                                  &nbsp;</td>
                              <td>
                                  <asp:Button ID="Button2" Visible="false" ValidationGroup="z" runat="server" 
                                      Width="160px" Text="Create New Group" onclick="Button2_Click" />
                                  &nbsp;
                                  <asp:Button ID="Button3" Visible="false" runat="server" Width="160px" 
                                      Text="Cancel" onclick="Button3_Click" />
                              </td>
                          </tr>
                      </table>

模态弹出框内的两个占位符

正如我在评论中注意到的,您已经在asp:ModalPopupExtender上设置了OkControlID="btnUpdate",并且该控件仅存在于第一个占位符上。所以当你隐藏第一个占位符的时候你会让模态失效因为你需要那个按钮完全发挥作用