2012-06-27 43 views
1

我在更新面板中保存了2个面板控件(带有文本框和按钮),这样我只需要一次显示1个面板控件。当我点击按钮时,下一个asp面板应该隐藏旧的asp面板。我无法推测出来。这里是代码...更新面板中的2个面板控件

<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> 

回答

0

如果使用ASP:MultiView,你会不会更好?然后,您一次显示一个视图,并且与它关联的互斥绑定。

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

你会使用多视图里面的UpdatePanel和设置有效收视基础上按一下按钮会更好。这里有一个tutorial

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

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; 

    } 

希望它会给你所需的结果你寻找。