show div取决于在文本框中输入的数字和单击按钮

时间:2014-01-21 06:35:10

标签: c# javascript jquery asp.net textbox

我有jQuery对话框,如果用户点击#buttonDialog对话框会出现,他们将被要求提供他们的住址和地址。我的问题是,如果用户输入#textHouseOccupant #divOccupantProfile中的号码,则会显示取决于#textHouseOccupant中输入的号码。例如,用户在#textHouseOccupant中输入5并单击按钮#btnAddOccupant,将显示5 #divOccupantProfile

jQuery对话框

<table>
<tr>
  <td><div id="divresident" runat="server" visible="false">
  <table style="margin-top:10px; margin-bottom:10px">
  <tr>
    <td width="300" style="text-align:left"><asp:Label ID="lbAddress" runat="server" Text="Address"></asp:Label></td>
    <td width="300"><asp:TextBox ID="txtAddress" class="basetxt" runat="server" Width="290"></asp:TextBox></td>
  </tr>
  <tr>
    <td style="text-align:left"><asp:Label ID="lbHouseOccupant" runat="server" Text="Number of House occupant"></asp:Label></td>
    <td><asp:TextBox ID="txtHouseOccupant" class="basetxt" runat="server" Width="290"></asp:TextBox></td>
   </tr>
   <tr>
     <td style="text-align:left"><asp:Button ID="btnAddOccupant" runat="server" Text="+" />
     <asp:Label ID="lbAddOccupant" runat="server" Text="Add Occupant"></asp:Label></td>
   </tr>
   <tr>
     <td>
     <div id="divShowFormHere"></div>
     </td>
   </tr>
   </table>
   </div></td>
 </tr>
 </table>

#divOccupantProfile

<div id="divOccupantProfile">

<asp:Label ID="OPfamilyname" runat="server" Text="Family Name"></asp:Label>
<asp:TextBox ID="textOPfamilyname" runat="server"></asp:TextBox><br />

<asp:Label ID="OPfirstname" runat="server" Text="First Name"></asp:Label>
<asp:TextBox ID="textOPfirstname" runat="server"></asp:TextBox><br />

<asp:Label ID="OPmiddlename" runat="server" Text="Middle Name"></asp:Label>
<asp:TextBox ID="textOPmiddlename" runat="server"></asp:TextBox><br />

<asp:Label ID="OPmaritalstatus" runat="server" Text="Marital Status"></asp:Label>
<asp:DropDownList ID="ddlOPmaritalstatus" runat="server" >
    <asp:ListItem></asp:ListItem>
    <asp:ListItem>Married</asp:ListItem>
    <asp:ListItem>Single</asp:ListItem>
    <asp:ListItem>Divorced</asp:ListItem>
</asp:DropDownList><br />

<asp:Label ID="OPoccupation" runat="server" Text="Occupation"></asp:Label>
<asp:TextBox ID="textOPoccupation" runat="server"></asp:TextBox><br />

<asp:Label ID="OPrelationship" runat="server" Text="Relationship"></asp:Label>
<asp:DropDownList ID="ddlOPrelationship" runat="server" >
    <asp:ListItem></asp:ListItem>
    <asp:ListItem>Wife</asp:ListItem>
    <asp:ListItem>Daughter</asp:ListItem>
    <asp:ListItem>Son</asp:ListItem>
    <asp:ListItem>Father</asp:ListItem>
    <asp:ListItem>Mother</asp:ListItem>
    <asp:ListItem>House helper</asp:ListItem>
    <asp:ListItem>Driver</asp:ListItem>
</asp:DropDownList>

</div>

1 个答案:

答案 0 :(得分:0)

就个人而言,我会以不同的方式处理这种情况。我通常有一个按钮/图标来添加额外的占用者。 Asp.NET MVC更容易处理这些场景,但在Web窗体中这里有一个链接,告诉你如何操作,诀窍是让ViewState记住你添加的每个新控件,否则任何回发都会删除它们:

  

http://www.codeproject.com/Articles/502251/How-to-create-controls-dynamically-in-ASP-NET-and