Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

Here i try to create dynamic text box in panel it created successfully but some problem in get value

my code

XML
<table class="style1" style="border:Solid 2px #5272B8; border-top-width:0px;" cellspacing="0">
     <tr style="background-color:#507CD1; color:Black;"><td class="style85">&nbsp;</td>
     <td align="left">
             <b>Add Here</b>
         </td>
         <td align="right">
            <asp:ImageButton ID="ImageButton3" runat="server" Height="16px"
                 ImageUrl="Images/closeicon.png" style="margin-right:0px;" Width="16px" />
         </td>
         <tr>
             <td>
                 &nbsp;</td>
             <td align="left">
                 Category:&nbsp;
                 <asp:Label ID="lblcategorypopup" runat="server" Text="Label" Font-Bold="true"></asp:Label>
                 &nbsp;&nbsp;&nbsp;Model:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Label ID="lblmodelpopup" runat="server" Text="Label" Font-Bold="true"></asp:Label></td>
             <td align="right">
                 &nbsp;</td>
         </tr>
         <tr>
             <td>
                 &nbsp;</td>
             <td align="left">
                 <asp:Panel ID="panelserial" runat="server">
                 </asp:Panel>
             </td>
             <td align="right">
                 &nbsp;</td>
         </tr>
         <tr>
             <td>
                 &nbsp;</td>
             <td align="left">
                 <asp:Button ID="btnaddpopup" runat="server" Text="Add" CssClass="button2"
                     onclick="btnaddpopup_Click" />
             </td>
             <td align="right">
                 &nbsp;</td>
         </tr>
         </table>

cs code:

C#
int n = Convert.ToInt32(txtqunty.Text);
           for (int i = 0; i < n; i++)
           {
               TextBox MyTextBox = new TextBox();
               //Assigning the textbox ID name
               MyTextBox.ID = "txtserialnum" + "" + ViewState["num"] + i;
               MyTextBox.Width = 200;
               MyTextBox.Height = 15;
               MyTextBox.TextMode = TextBoxMode.SingleLine;
               panelserial.Controls.Add(MyTextBox);

               Literal li = new Literal();
               li.Text = "";
               panelserial.Controls.Add(li);
           }
           Modelpopserial.Show();


C#
protected void btnaddpopup_Click(object sender, EventArgs e)
    {
        TextBox txtsno = (TextBox)panelserial.FindControl("MyTextBox");
    }
Posted
Updated 23-Jul-14 21:24pm
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900