Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hai,
i am not getting how to insert dynamic text boxes data to database on a button click am getting dynamic textboxes, onclick of submit button i want to insert data into database. help me with the code please.

my .aspx page

ASP.NET
<legend>Organisation /Company Contacts</legend>
<asp:ScriptManager ID="scrptmgr1" runat="server" />
<asp:UpdatePanel ID="updatepnl1" runat="server" UpdateMode="Conditional">
<triggers>
 <asp:AsyncPostBackTrigger ControlID="btn1" EventName="Click" />
</triggers>
<contenttemplate>
<asp:Table ID="tbl1" runat="server" Height="48px" Width="330px">
 <asp:TableRow ID="tr1" runat="server">
 <asp:TableCell ID="r1_tc1" runat="server">
<asp:Label ID="regdet_llno_lbl" runat="server">Land Line Number:


<asp:TableCell ID="r1_tc2" runat="server" RowSpan="2">
<asp:TextBox ID="regdet_llno_txt" runat="server" />
 <asp:RegularExpressionValidator ID="validator1" runat="server" ControlToValidate="regdet_llno_txt" ErrorMessage="Only numbers are allowed" ValidationExpression="^\d+$">


<asp:TableCell ID="r1_tc3" runat="server">
<asp:Button ID="btn1" runat="server" Text="add" CausesValidation="false" OnClick="btn1_Click" />
 </contenttemplate>

my .cs page
C#
protected void btn1_Click(object sender, EventArgs e)
{
    int a = 3;
    for (; a <= 5; a++)
    {
        TextBox lndline = new TextBox();
        lndline.ID = "lndline_txt" + a;
        r1_tc2.Controls.Add(lndline);
        Literal li1 = new Literal();
        li1.Text = "";
        r1_tc2.Controls.Add(li1);
    }
    int b = 1;
    if (b==1)
    {
        btn1.Enabled = false;
    }
}
Posted
Updated 18-May-12 23:08pm
v2

1 solution

You need to re generate this boxes in Page Load event.

Put the Box generation code in a fucntion.
call this function on the button click and in page load both.

then in save method you will be able to get the values of the text boxes
dynamically generated.
 
Share this answer
 

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