By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,345 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,345 IT Pros & Developers. It's quick & easy.

Accessing dynamically created components in C#

P: n/a
All,

I created dynamically part of a table and its components such as text
boxes etc...
As you can see in the example below I created txtAddress textbox...
Everything works perfectly until the point where I need to save the
textbox input (normally I would use txtAddress.Text). But in my
btnContinue_Click class I can't because It's out of the scope.
Question: How can I access the dynamically created textboxes and save
the inputs?

public void Address()
{
.....
foreach (DataRow dataRow in objDataTable_address.Rows)
{
TableRow tr0 = new TableRow();
TableCell tc0 = new TableCell();
TextBox txtAddress = new TextBox();
txtAddress.ID = dataRow["AddressID"].ToString();
txtAddress.Width = 250;
tc0.Controls.Add(txtAddress);
txtAddress.Text = dataRow["Address"].ToString(); ........

protected void btnContinue_Click(object sender, EventArgs e)
{
param = command0.Parameters.Add("@FirstName",
SqlDbType.VarChar,25);
param.Direction = ParameterDirection.Input;
param.Value = txtFirstName.Text;
Thanks for all and any help,
draku

Feb 5 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
do a FindControl on the controls collection

TextBox myBox = this.Controls.FindControl("controlname")
--
Terry Burns
http://TrainingOn.net
<dr****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
All,

I created dynamically part of a table and its components such as text
boxes etc...
As you can see in the example below I created txtAddress textbox...
Everything works perfectly until the point where I need to save the
textbox input (normally I would use txtAddress.Text). But in my
btnContinue_Click class I can't because It's out of the scope.
Question: How can I access the dynamically created textboxes and save
the inputs?

public void Address()
{
....
foreach (DataRow dataRow in objDataTable_address.Rows)
{
TableRow tr0 = new TableRow();
TableCell tc0 = new TableCell();
TextBox txtAddress = new TextBox();
txtAddress.ID = dataRow["AddressID"].ToString();
txtAddress.Width = 250;
tc0.Controls.Add(txtAddress);
txtAddress.Text = dataRow["Address"].ToString(); ........

protected void btnContinue_Click(object sender, EventArgs e)
{
param = command0.Parameters.Add("@FirstName",
SqlDbType.VarChar,25);
param.Direction = ParameterDirection.Input;
param.Value = txtFirstName.Text;
Thanks for all and any help,
draku

Feb 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.