469,890 Members | 1,428 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

Access dynamically created TextBoxes

I want to know the code how to save data from dynamically created textboxes.
The code I have written is this in whch I have dynamically created label and textboxes in a html table.The data in the label is from a table

The code I have written so far is

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         SqlCommand cmd = new SqlCommand("select * from Categories", cnn);
  4.         SqlDataReader dr;
  5.         cnn.Open();
  6.         dr = cmd.ExecuteReader();
  7.         int i = 1;
  8.         while (dr.Read())
  9.         {
  10.             row = new TableRow();
  11.  
  12.             cell = new TableCell();
  13.             label1 = new Label();
  14.             label1.Text = dr["CategoryName"].ToString();
  15.             cell.Text = label1.Text;
  16.             row.Cells.Add(cell);
  17.  
  18.             cell = new TableCell();
  19.             text = new TextBox();
  20.             text.ID = "text" + i;
  21.             cell.Controls.Add(text);
  22.             row.Cells.Add(cell);
  23.  
  24.             Table1.Rows.Add(row);
  25.             i++;
  26.  
  27.         }
  28.         cnn.Close();
  29.         dr.Close();
  30.     }
  31.  
can anyone tell how do i save data whch the user enter at run time
Dec 27 '08 #1
2 2026
Plater
7,872 Expert 4TB
Record the information when a postback occurs?
Dec 29 '08 #2
Frinavale
9,735 Expert Mod 8TB
Please check out this article on how to use dynamic controls in ASP.NET.

You are creating your TextBoxes in the Page Load event. The Page Load event happens after the ViewState for all of the controls on the page has been loaded...this means that the TextBoxes will not be loaded with the data that the user enters.

Take a quick look at the article and see if it helps you solve your problem.

-Frinny
Dec 29 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Bhavin | last post: by
3 posts views Thread by Forconi Boris via .NET 247 | last post: by
6 posts views Thread by Bjorn Sagbakken | last post: by
4 posts views Thread by =?Utf-8?B?RHlsYW5TbWl0aA==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.