Hi,
I have an drop downlist whic contains the products and a textbox for quantity. when i am selecting the dropdownlist and write the quantity value in the textboxes and click the Button1 textboxes are dynamically generating in the placeholder with labels according to quantity but when again i am selecting the other product from the dropdownlist then clickin the button then new textboxes are generating and previous textboes disappears. I needs the previou textboes also. how will i do. Please help.

protected void Button1_Click(object sender, EventArgs e)

{
   if (txtQuantity.Text != "")
            {
              for (int i =0; i < Convert.ToInt16(txtQuantity.Text);i++ )
               {

                    Label la = new Label();
                     la.Text = ddlProductName.SelectedItem.Value + i.ToString();
                     la.ID = "abc" +i;

                       PlaceHolder1.Controls.Add(la);

                     //la = FindControl(String.Format(i)) as Label;




                   // TextBox txtbox = new TextBox();
                      // txtbox.Text = "Textbox - " + i.ToString();


                     PlaceHolder1.Controls.Add(new LiteralControl("<input id='txt' name='Textbox"  + i  + "'type='text'  />"));
                       PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));

                   }
             }




}

One option is to not generate these controls on button click. Have them already present in the design, and set the visible property true/false depending on your logic. This way, the page will allow your objects to persist between postbacks.

send ur .aspx code please

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <%--</asp:PlaceHolder>--%>
<div>

<div>
    <table class="style32" bgcolor="White">
        <tr>
            <td atomicselection="True" class="style6" valign="top" bgcolor="White">
                <strong>Materials In -&gt; FSPL</strong></td>
        </tr>
        <tr>
            <td atomicselection="True" class="style165" valign="top" bgcolor="WhiteSmoke">
                <strong>Customer Details:</strong></td>
        </tr>
        <tr>
            <td atomicselection="True" class="style105" valign="top" bgcolor="White">
                &nbsp;</td>
        </tr>
        <tr>

            <td atomicselection="True" class="style64" valign="top" bgcolor="White" 
                style="color: #990000">
                <table class="style95">
                    <tr>
                        <td class="style151" valign="top">
                            &nbsp;</td>
                        <td class="style107" valign="top">
                <asp:Label ID="lblH2" runat="server" Text="Customer Name" CssClass="style4" 
                    Font-Size="8.5pt" ForeColor="Black"></asp:Label>
                        </td>
                        <td class="style107" valign="top">
                <asp:DropDownList ID="ddlCName" runat="server" AutoPostBack="true" 
                    OnSelectedIndexChanged="ddlCName_SelectedIndexChanged" CssClass="style59" 
                    Height="78px" Width="150px" BackColor="White">
                </asp:DropDownList>
                        </td>
                        <td class="style160" valign="top">
                <asp:Label ID="lblH3" runat="server" Text="Customer Location" CssClass="style4" 
                    Font-Size="8.5pt" ForeColor="Black"></asp:Label>
                        </td>
                        <td class="style162" valign="top">
                <asp:DropDownList ID="ddlCLocation" runat="server" CssClass="style59" 
                    Height="78px" Width="150px" BackColor="White" >
                </asp:DropDownList>
                        </td>
                        <td align="right" class="style140" valign="top">
                            &nbsp;</td>

                        <td align="left" class="style133" valign="top" colspan="2">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style106" valign="top" colspan="8" bgcolor="WhiteSmoke">
                            <strong>GatePass Details:</strong></td>
                    </tr>
                    <tr>
                        <td class="style106" valign="top" colspan="8" bgcolor="White">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style151" valign="top">
                            &nbsp;</td>
                        <td class="style107" valign="top">
                <asp:Label ID="lblH4" runat="server" Text="Gate Pass No" CssClass="style4" 
                    Font-Size="8.5pt"></asp:Label>
                        </td>
                        <td class="style107" valign="top">
                <asp:TextBox ID="txtGatePass" runat="server" Width="150px" BackColor="White" 
                    CssClass="style63" Height="20px" 
                    ></asp:TextBox>
                        &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                ControlToValidate="txtGatePass" ErrorMessage="*"></asp:RequiredFieldValidator>
                        </td>
                        <td class="style160" valign="top">
                <asp:Label ID="Label5" runat="server" CssClass="style4" Text="Gate Pass Date" 
                    Font-Size="8.5pt"></asp:Label>
                        </td>
                        <td class="style162" valign="top">
                <asp:TextBox ID="TextBox1" runat="server" Width="150px" Height="20px"></asp:TextBox>
                            <asp:ImageButton ID="ImageButton4" runat="server" Height="16px" 
                    ImageUrl="~/imagesCAFW0TXB.jpg" Width="24px" 
                    onclick="ImageButton4_Click" />
                        </td>
                        <td align="left" class="style140" valign="top" colspan="2" rowspan="4">
                <asp:Calendar ID="Calendar1" runat="server" BackColor="White" 
                    BorderColor="#3366CC" DayNameFormat="Shortest" Font-Names="Verdana" 
                    Font-Size="8pt" ForeColor="#003399" Height="16px" Width="136px" 
                    BorderWidth="1px" CellPadding="1" ondayrender="Calendar1_DayRender" 
                    onselectionchanged="Calendar1_SelectionChanged">
                    <DayHeaderStyle BackColor="#99CCCC" 
                        ForeColor="#336666" Height="1px" />
                    <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
                    <OtherMonthDayStyle ForeColor="#999999" />
                    <SelectedDayStyle BackColor="#CC99FF" ForeColor="#CCFF99" Font-Bold="True" />
                    <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
                    <TitleStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="10pt" 
                        ForeColor="Black" Height="25px" BorderColor="Black" 
                        BorderWidth="1px" />
                    <TodayDayStyle BackColor="#FFCC00" ForeColor="White" />
                    <WeekendDayStyle BackColor="#CCCCCC" />
                </asp:Calendar>
                        </td>
                        <td valign="top" class="style154" rowspan="4">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style151">
                            &nbsp;</td>
                        <td class="style107">
                <asp:Label ID="Label6" runat="server" Font-Size="8.5pt" Text="Gate Pass Remark" 
                                Font-Bold="False" style="color: #000000; font-family: Verdana"></asp:Label>
                        </td>
                        <td class="style107">
                <asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" 
                     Width="150px"></asp:TextBox>
                        </td>
                        <td class="style160" colspan="2">
                            <asp:CompareValidator ID="CompareValidator1" runat="server" 
                                ControlToValidate="TextBox1" ErrorMessage="Plese Enter a valid Date" 
                                Font-Bold="False" ForeColor="#003366" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator>
                        </td>
                    </tr>
                    <tr>
                        <td class="style163" rowspan="2">
                            </td>
                        <td class="style164" valign="top">
                            <asp:Label ID="Label9" runat="server" Font-Size="8.5pt" Text="Attachment"></asp:Label>
                        </td>
                        <td class="style164" valign="top">
                <asp:FileUpload ID="FileUpload1" runat="server" CssClass="style63" BackColor="#CCCCCC" />
                            <b>
                            <asp:Button ID="Button3" runat="server" BackColor="#F4F4F4" CssClass="style4" 
                                Font-Size="8.5pt" onclick="Button3_Click" Text="Upload" />

                            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                                ControlToValidate="FileUpload1" 
                                ErrorMessage="Only Pdf/JPEG/GIF files are uploaded" 
                                style="font-family: Verdana; font-size: x-small; color: #003366; font-weight: 700" 
                                ValidationExpression="^.*\.(jpg|JPG|gif|GIF|pdf|PDF)$"></asp:RegularExpressionValidator>


                </b>
                        </td>
                        <td class="style108" colspan="2" rowspan="2" valign="top">
                            <b>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" 
                    BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" 
                    GridLines="Vertical" Height="16px" Width="16px" Font-Size="8.5pt" 
                    style="font-family: Verdana" ForeColor="Black" UseAccessibleHeader="False">
    <AlternatingRowStyle BackColor="#CCCCCC" />
    <Columns>
        <asp:BoundField DataField="Text" HeaderText="File Name" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="lnkDownload" Text = "Download" CommandArgument = '<%# Eval("Value") %>' runat="server" OnClick = "DownloadFile"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID = "lnkDelete0" Text = "Delete" 
                    CommandArgument = '<%# Eval("Value") %>' runat = "server" 
                    OnClick = "DeleteFile" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="#CCCCCC" Font-Bold="True" ForeColor="Black" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>


                            <br />


                </b>
                            <br />

                        </td>
                    </tr>
                    <tr>
                        <td class="style164" valign="top">
                <asp:Label ID="Label8" runat="server" Font-Size="8.5pt" Text="Vendor Name" 
                                ForeColor="Black" style="font-family: Verdana"></asp:Label>
                        </td>
                        <td class="style164" valign="top">
                <asp:DropDownList ID="DropDownList1" runat="server" 
                    DataSourceID="SqlDataSource1" DataTextField="Vendor_Name" 
                    DataValueField="Vendor_Name" Height="78px" Width="150px">
                </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td class="style137" colspan="8" bgcolor="WhiteSmoke">
                            GatePass Product Details:</td>
                    </tr>
                    <tr>
                        <td class="style137" colspan="8" bgcolor="White">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style157" valign="top">
                            &nbsp;</td>
                        <td class="style130" valign="middle">
                <asp:Label ID="Label7" runat="server" Font-Size="8.5pt" 
                    style="color: #000000; font-family: Verdana;" Text="Product Name"></asp:Label>
                        </td>
                        <td class="style130" valign="top">
                <asp:DropDownList ID="ddlProductName" runat="server" CssClass="style59" 
                    Height="20px" Width="150px" BackColor="White">
                </asp:DropDownList>
                        </td>
                        <td class="style161" valign="top" colspan="4">
                <asp:Label ID="lblQuantity" runat="server" Text="Quantity" CssClass="style4" 
                    Font-Size="8.5pt"></asp:Label>
                <asp:TextBox ID="txtQuantity" runat="server"  Width="150px" 
                    Height="20px" BackColor="White" 
                    ></asp:TextBox>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
                    Text="Generate " CssClass="style4" BackColor="#F4F4F4" 
                    Width="72px" Height="22px" Font-Size="8.5pt" />

                        </td>
                        <td valign="top" class="style158">
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:FSPL_AMCConnectionString %>" 

                                SelectCommand="SELECT  distinct [Vendor_Name] FROM [VandorDetail] where [Status]='Active'">
                </asp:SqlDataSource>
                        </td>
                    </tr>
                    <tr>
                        <td class="style157">
                            </td>
                        <td class="style130">
                <asp:Label ID="lblSerials" runat="server" Text="Serial Numbers" 
                    CssClass="style4" Font-Bold="False" Font-Size="8.5pt"></asp:Label>
                        </td>
                        <td class="style130">
                <asp:PlaceHolder ID="PlaceHolder1" runat="server" ViewStateMode="Enabled"></asp:PlaceHolder>
                        </td>
                        <td class="style131" colspan="4">
                &nbsp;&nbsp;&nbsp;
                        </td>
                        <td class="style158">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style157">
                            &nbsp;</td>
                        <td class="style130" colspan="2">
                <asp:Button ID="Button2" runat="server" BackColor="#F4F4F4" CssClass="style4" 
                    Font-Size="8.5pt" Height="22px" onclick="Button2_Click" Text="Add" 
                    Width="76px" />
                        </td>
                        <td class="style131" colspan="4">
                <asp:Button ID="Button4" runat="server" BackColor="#F4F4F4" CssClass="style4" 
                    Font-Size="8.5pt" Height="22px" onclick="Button4_Click" Text="Reset" 
                    Width="75px" />
                        </td>
                        <td class="style158">
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style125" colspan="8" bgcolor="WhiteSmoke">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td class="style104">
                            &nbsp;</td>
                        <td colspan="7" class="style132">
                <asp:GridView ID="gdvProducts" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="gdvProducts_RowCancelingEdit"
                    OnRowEditing="gdvProducts_RowEditing" OnRowUpdating="gdvProducts_RowUpdating"
                    OnRowDataBound="gdvProducts_RowDataBound" 
                    onrowdeleting="gdvProducts_RowDeleting" Width="621px" Font-Size="8.5pt" 
                     style="font-family: Verdana; color: #000000;" CellPadding="3" ForeColor="Black" 
                                GridLines="Vertical" BackColor="White" BorderColor="#999999" 
                                BorderStyle="Solid" BorderWidth="1px" 
                                onselectedindexchanged="gdvProducts_SelectedIndexChanged">
                    <AlternatingRowStyle BackColor="#CCCCCC" />
                    <Columns>
                        <asp:TemplateField HeaderText="ID" ItemStyle-Width="10%" HeaderStyle-Font-Size="11px">
                            <ItemTemplate>
                                <asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
                            </ItemTemplate>

<HeaderStyle Font-Size="11px"></HeaderStyle>

<ItemStyle Width="10%"></ItemStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Product Name" ItemStyle-Width="20%" HeaderStyle-Font-Size="11px">
                            <ItemTemplate>
                                <asp:Label ID="lblProduct" runat="server" Text='<%# Bind("Product_Name")%>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                            <asp:TextBox ID="txt_Edit_Product" runat="server" Text='<%# Bind("Product_Name") %>'></asp:TextBox>
                            </EditItemTemplate>

<HeaderStyle Font-Size="11px"></HeaderStyle>

<ItemStyle Width="20%"></ItemStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Serial Number" ItemStyle-Width="20%" HeaderStyle-Font-Size="11px">
                            <ItemTemplate>
                                <asp:Label ID="lblSerial" runat="server" Text='<%# Bind("SerialNo")%>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                           <%--<asp:PlaceHolder ID="PlaceHolder1" runat="server">--%>
                           <asp:TextBox ID="tb1" enabled="true" runat="server" 
                                    Text='<%# (gdvProducts.PageSize * gdvProducts.PageIndex) + Container.DisplayIndex + 1 %>'></asp:TextBox>
                            <%--</asp:PlaceHolder>--%>
                            </EDitItemTemplate>

<HeaderStyle Font-Size="11px"></HeaderStyle>

<ItemStyle Width="20%"></ItemStyle>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Action" ControlStyle-ForeColor="Black" ItemStyle-Width="20%"
                            HeaderStyle-Font-Size="11px">
                            <ItemTemplate>

                                <asp:ImageButton CssClass="txtBtn" ID="lnkEdit" runat="server" CommandName="Edit"
                                    ImageUrl="~/images/edit.gif" ToolTip="Edit" PostBackUrl="~/Role Type.aspx" Visible="True" />&nbsp;&nbsp;
                                 <asp:ImageButton CssClass="txtBtn" ID="lnkDelete" runat="server" CommandName="Delete"
                                    CommandArgument='' OnClientClick="javascript:return confirm('Are you sure you want to delete the record?')"
                                    ImageUrl="~/images/icon_delete.gif" ToolTip="Delete" PostBackUrl="~/Role Type.aspx" Visible="True" />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:ImageButton CssClass="txtBtn" ID="lnkUpdate" runat="server" CausesValidation="true"
                                    CommandName="Update" CommandArgument='' ImageUrl="~/images/icon_update.png" ToolTip="Update" />
                                <asp:ImageButton CssClass="txtBtn" ID="lnkCancel" runat="server" CausesValidation="true"
                                    CommandName="Cancel" CommandArgument='' ImageUrl="~/images/icon_cancel.gif" ToolTip="Cancel" />
                            </EditItemTemplate>
                            <ControlStyle ForeColor="Black"></ControlStyle>

<HeaderStyle Font-Size="11px"></HeaderStyle>

<ItemStyle Width="20%"></ItemStyle>
                        </asp:TemplateField>
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <HeaderStyle BackColor="#CCCCCC" Font-Bold="True" ForeColor="Black" />
                    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#808080" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#383838" />
                </asp:GridView>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        </table>

    </div>
    </div>
  <%-- </fieldset>--%>

</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="head">
    <style type="text/css">
        .style4

        { font-family:Verdana; 
font-size:medium;
           text-align: center;
            color: #000000;
        }
        .style32
        {   overflow:hidden;
            display:inline-block;
            width: 1042px;
            height: 586px;
        }
        .style59
        {
        }
        .style63
        {
            font-weight: bold;
            font-family: Verdana;
            font-size: small;
        }
        .style64
        {    
            font-family: Aharoni;
            font-size: medium;
            text-align: left;
            height: 333px;
        }
        .style95
        {
            width: 1246px;
            height: 440px;
        }
        .style104
        {
            font-family: Verdana;
            font-size: small;
            color: #000000;
            font-weight: 700;
            height: 126px;
            width: 10px;
        }
        .style105
        {
            text-align: left;
            height: 20px;
            font-family: Verdana;
            font-size: small;
            color: #000000;
        }
        .style106
        {
            font-family: Verdana;
            font-size: small;
            color: #000000;
            font-weight: 700;
            height: 13px;
        }
        .style107
        {
            width: 134px;
            font-family: Verdana;
            font-size: x-small;
            color: #000000;
            height: 29px;
        }
        .style108
        {
            color: #000000;
            font-family: Verdana;
            font-size: small;
            height: 7px;
        }
        .style125
        {
            font-family: Verdana;
            font-size: small;
            color: #000000;
            font-weight: 700;
        }
        .style130
        {
            width: 134px;
            font-family: Verdana;
            font-size: x-small;
            color: #000000;
            height: 30px;
        }
        .style131
        {
            color: #000000;
            font-family: Verdana;
            font-size: small;
            height: 30px;
            text-align: left;
        }
        .style132
        {
            height: 126px;
        }
        .style133
        {
            height: 29px;
        }
        .style137
        {
            font-family: Verdana;
            font-size: small;
            color: #000000;
            font-weight: 700;
            height: 18px;
        }
        .style140
        {
        }
        .style151
        {
            font-family: Verdana;
            font-size: small;
            color: #000000;
            font-weight: 700;
            height: 29px;
            width: 10px;
        }
        .style154
        {
            width: 205px;
        }
        .style157
        {
            font-family: Verdana;
            font-size: small;
            color: #000000;
            font-weight: 700;
            height: 30px;
            width: 10px;
        }
        .style158
        {
            height: 30px;
            width: 205px;
        }
        .style160
        {
            color: #000000;
            font-family: Verdana;
            font-size: small;
            height: 29px;
            width: 128px;
        }
        .style161
        {
            color: #000000;
            font-family: Verdana;
            font-size: small;
            height: 30px;
            }
        .style162
        {
            color: #000000;
            font-family: Verdana;
            font-size: small;
            height: 29px;
            width: 176px;
        }
        .style163
        {
            font-family: Verdana;
            font-size: small;
            color: #000000;
            font-weight: 700;
            height: 7px;
            width: 10px;
        }
        .style164
        {
            width: 134px;
            font-family: Verdana;
            font-size: x-small;
            color: #000000;
            height: 7px;
        }
        .style165
        {
            text-align: left;
            height: 14px;
            font-family: Verdana;
            font-size: small;
            color: #000000;
        }
        </style>
</asp:Content>

Hi, you just need to re-create the dynamic objects on the page postback

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.