Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am creating textboxes in each button click at run time(dynamically). I have no idea ,how to get the values from each text box and save it in database. Any number of textbox can be created as per users's wish. How can i solve this,,Please help me. My code is below.
Thanks

int myCount;
protected void lbtnadd_Click(object sender, EventArgs e)
        {
            if (ViewState["addmoreEdu"] != null)
            {
                myCount = (int)ViewState["addmoreEdu"];
            }
            myCount++;
            ViewState["addmoreEdu"] = myCount;
        

            for (int i = 0; i < myCount; i++)
            {
               TextBox txtboxcustom = new TextBox();
                Literal newlit = new Literal();
                newlit.Text = "<br />";
                txtboxcustom.ID = "txtLandline" + i.ToString();
                PnlLndline.Controls.Add(txtboxcustom);
                PnlLndline.Controls.Add(newlit);
            }
        }
Posted

use request.form to get value of text box which is created dynamically


C#
for (int i = 0; i < 5; i++)
       {
lblText.Text = lblText.Text +  Request.Form["txtLandline" + .ToString()].ToString() + "<br />";



       }
 
Share this answer
 
Find the Each control in panel and you can get the values for that control
Please try following piece of code

C#
foreach (Control item in testpnl.Controls)
            {

                if (item.GetType().Name == "TextBox")
                {
                    string val = ((TextBox)item).Text;
                }

            }
 
Share this answer
 
Comments
jacobjohn196 18-Jun-13 2:11am    
Thanks,, Suppose i'm creating three textboxes t1,t2,t2 and entered a,b,c in each textbox respectievely. Then It shows abc in t1.
Vipin kumar.P 18-Jun-13 3:34am    
Can you paste the code piece so that we can have a look
hi...
please reference this from following link
http://forums.asp.net/t/1505091.aspx/1[^]
 
Share this answer
 
Try this
C#
string cntrlid= string.Empty;
            for (int i = 0; i <= form1.Controls.Count; i++)
            {
                cntrlid = " txtLandline" + i.ToString();
                TextBox txt = form1.FindControl(controlid) as TextBox;
                if (txt!= null)
               {
                      ------------
               }
}
 
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