更新面板中的2个asp面板控件

时间:2012-06-27 20:50:23

标签: asp.net

我在更新面板中保留了2个asp面板控件(带有文本框和按钮),这样我一次只能显示1个。当我点击按钮时,下一个asp面板应该可见,隐藏旧的asp面板。我无法弄清楚..这是代码......

<asp:UpdatePanel ID="updatepnlSSN" ChildrenAsTriggers="false" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
     <asp:Panel ID="pnlSSNLookup" runat="server" BackColor="#EEE6DF" BorderColor="#274F73"
                            BorderStyle="Outset">
        <table>
           <tr>
            <td colspan="3">
   <asp:Label ID="lblMsg" runat="server" ForeColor="#713C2C"></asp:Label>
            </td>
           </tr>
           <tr>
            <td>
   <asp:Label ID="lblStudentID" runat="server" Text="State Student ID:" ForeColor="#274F73" ToolTip="State Student ID Label"></asp:Label>
            </td
            <td>
 &nbsp;&nbsp;&nbsp;
   <asp:TextBox ID="txtStudentID" runat="server" ToolTip="Enter the student's state ID number" AccessKey="i" TabIndex="1"></asp:TextBox>
            </td>
            <td>
   <asp:RegularExpressionValidator ID="valStudentID" runat="server" ControlToValidate="txtStudentID" ErrorMessage="Please enter numeric only" ValidationExpression="[0-9]+" ForeColor="#713C2C" Display="Dynamic">
</asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="valStdntID" runat="server" ControlToValidate="txtStudentID" Display="Dynamic" ErrorMessage="Please enter a State Student ID" ForeColor="#713C2C"></asp:RequiredFieldValidator>
           </td>
         </tr>
         <tr>
           <td>
 <asp:Label ID="lblFName" runat="server" Text="Student Legal First Name:" ForeColor="#274F73" ToolTip="First Name Label"></asp:Label>
           <td>
           <td>
&nbsp;&nbsp;&nbsp;
 <asp:TextBox ID="txtFName" runat="server" AccessKey="f" TabIndex="2" ToolTip="Enter the Student's First Name"></asp:TextBox>
          </td>
                                    <td>
   <asp:RequiredFieldValidator ID="valFirstName" runat="server" ControlToValidate="txtFName" Display="Dynamic" ErrorMessage="Please enter the student's first name." ForeColor="#713C2C"></asp:RequiredFieldValidator>
          </td>
        </tr>
        <tr>
          <td>
   <asp:Label ID="lblDOB" runat="server" ForeColor="#274F73" Text="Student Date of Birth </br> (mm/dd/yyyy)" ToolTip="STudent's date of birth label"></asp:Label>
          </td>
          <td>
 <div style="position: relative;">
 &nbsp;&nbsp;&nbsp;
  <asp:TextBox ID="txtDOB" runat="server" AccessKey="d" TabIndex="3" ToolTip="Enter the student's date of birth"></asp:TextBox>
  <cc1:CalendarExtender ID="txtDOB_CalendarExtender" runat="server" Enabled="True" TargetControlID="txtDOB" PopupPosition="Right" Format="MM/dd/yyyy">
    </cc1:CalendarExtender>
     </div>
                                    </td>
                                    <td>
 <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtDOB" ErrorMessage="Please enter a valid date:  mm/dd/yyyy" ForeColor="#713C2C" MaximumValue="01/01/2075" MinimumValue="01/01/1970" Type="Date" Display="Dynamic"></asp:RangeValidator>
  <asp:RequiredFieldValidator ID="valStudentDOB" runat="server" ControlToValidate="txtDOB" Display="Dynamic" ErrorMessage="Please enter the student's date of birth" ForeColor="#713C2C"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        &nbsp;
                                    </td>
                                </tr>
                                <tr>
                                    <td>
 <asp:Button ID="btnSearchSSN" runat="server" Text="Search" AccessKey="s" TabIndex="4" ToolTip="Begin student search" />
                                    </td>
                                </tr>
                            </table>
                        </asp:Panel>
                        </td> </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                        </tr>
                        <tr>
                            <td style="padding: 0 10px 0 10px">
 <asp:Panel ID="pnlSSNEntry" runat="server" BackColor="#EEE6DF" BorderColor="#274F73" BorderStyle="Outset" Visible="False" Height="110px">
   <table align="left">
                                        <tr>
           <td colspan="3">
   <asp:Label ID="lblSSnText" runat="server" ForeColor="#274F73" Text="Please enter the SSN for:  "></asp:Label>
   <asp:Label ID="lblSSNName" runat="server" ForeColor="#274F73"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">
   <asp:Label ID="lblSSNSubmitMsg" runat="server" ForeColor="#713C2C"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
   <asp:Label ID="lblSSN0" runat="server" ForeColor="#274F73" Text="Social Security Number:   "></asp:Label>
                                            </td>
                                            <td>
  &nbsp;&nbsp;&nbsp;
   <asp:TextBox ID="txtArea" runat="server" AccessKey="a" MaxLength="3" TabIndex="5" ToolTip="Enter the student's SSN area number" Width="29px"></asp:TextBox>
 &nbsp;&nbsp;
     <asp:TextBox ID="txtGroup" runat="server" AccessKey="g" MaxLength="2" TabIndex="6" ToolTip="Enter the student's SSN group number" Width="22px"></asp:TextBox>
                                                &nbsp;&nbsp;
    <asp:TextBox ID="txtSerial" runat="server" AccessKey="r" MaxLength="4" TabIndex="7" ToolTip="Enter the student's SSN serial number" Width="35px"></asp:TextBox>
                                            </td>
                                            <td>
   <asp:Label ID="lblSSNError" runat="server" ForeColor="#713C2C" Text="Please enter a valid Social Security Number" Visible="False"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
     <asp:Button ID="btnSSN" runat="server" Text="Submit SSN" AccessKey="n" TabIndex="8" ToolTip="Submit the student's SSN" />
                                            </td>
                                        </tr>
                                    </table>
                                </asp:Panel>
                    </ContentTemplate>
                    <Triggers>
   <asp:AsyncPostBackTrigger ControlID="btnSearchSSN" EventName="Click" />
   <asp:AsyncPostBackTrigger ControlID="btnSSN" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>

3 个答案:

答案 0 :(得分:0)

最好在UpdatePanel中使用MultiView并根据按钮点击设置ActiveView。这是tutorial

简而言之,MultiView是面板的包装。它包含可以激活的View对象的集合。在任何给定时间只能看到一个视图。

答案 1 :(得分:0)

使用ASP:MultiView会不会更好。然后,您一次显示一个视图,它带有与之关联的互斥绑定。

<asp:MultiView>
    <asp:View>
       View 1
    </asp:View>
     <asp:View>
       View 2
    </asp:View>
</asp:MultiView>

答案 2 :(得分:0)

上面的答案提出了解决上述问题的一种很好的方法,但是如果你真的想这样做,那就试着在按钮点击事件上添加代码,比如

protected void btnSearchSSN_Click(object sender, EventArgs e)
  {
      pnlSSNLookup.Visible = false;
      this.pnlSSNEntry.Visible = true;
  }
  protected void btnSSN_Click(object sender, EventArgs e)
  {
      pnlSSNEntry.Visible = false;
      this.pnlSSNLookup.Visible = true;

  }

希望它能为您提供所需的结果。