473,657 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing dynamically created components in C#

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_Cli ck 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_ad dress.Rows)
{
TableRow tr0 = new TableRow();
TableCell tc0 = new TableCell();
TextBox txtAddress = new TextBox();
txtAddress.ID = dataRow["AddressID"].ToString();
txtAddress.Widt h = 250;
tc0.Controls.Ad d(txtAddress);
txtAddress.Text = dataRow["Address"].ToString(); ........

protected void btnContinue_Cli ck(object sender, EventArgs e)
{
param = command0.Parame ters.Add("@Firs tName",
SqlDbType.VarCh ar,25);
param.Direction = ParameterDirect ion.Input;
param.Value = txtFirstName.Te xt;
Thanks for all and any help,
draku

Feb 5 '06 #1
1 1374
do a FindControl on the controls collection

TextBox myBox = this.Controls.F indControl("con trolname")
--
Terry Burns
http://TrainingOn.net
<dr****@gmail.c om> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.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_Cli ck 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_ad dress.Rows)
{
TableRow tr0 = new TableRow();
TableCell tc0 = new TableCell();
TextBox txtAddress = new TextBox();
txtAddress.ID = dataRow["AddressID"].ToString();
txtAddress.Widt h = 250;
tc0.Controls.Ad d(txtAddress);
txtAddress.Text = dataRow["Address"].ToString(); ........

protected void btnContinue_Cli ck(object sender, EventArgs e)
{
param = command0.Parame ters.Add("@Firs tName",
SqlDbType.VarCh ar,25);
param.Direction = ParameterDirect ion.Input;
param.Value = txtFirstName.Te xt;
Thanks for all and any help,
draku

Feb 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2918
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have a WebForm with some textboxes, dropdownlists, a panel, imagebutton and so on. When I click on the image button (which was created at design time) I dynamically build a table. In each of row of that new table I put several cells and one cell...
1
3119
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
5
3051
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet explorer would do in this case. The headers I am getting are: Headers {Content-Disposition: attachment; filename="dynamic_file.mdb" Connection: close Cache-Control: private Content-Type: application/octet-stream
5
2864
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the elements in the form, including those that are added dynamically. I use document.getElementsByName('Field Name')to achieve the same.
1
2463
by: AndiSmith | last post by:
Hi guys, I wondered if anyone could help me with this problem, or even shed some light on the direction I need to take to resolve it? I'm using .NET 2.0 (C# flavor) to build a large user-based website. I've created an AJAX based user control, which is dynamically placed on a page (once, or multiple times) if the user has the correct permissions to receive it. It contains two drop down lists - employee value and partner value; and a...
2
3379
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and place it in the last cell of each row that I create dynamically using DOM methods. Everything is working well (that is, just like the original example) except for something related to the function behind my link. The link simply calls a function...
1
1880
by: Grega | last post by:
Hi all, I am trying to create a VB smart device application. I create few buttons dynamically on form_load... something like this: Dim WithEvents BtnOperate As New OpenNETCF.Windows.Forms.Button2 Me.BtnOperate.Location = New System.Drawing.Point(20, 20) Me.BtnOperate.Size = New System.Drawing.Size(150, 150) Me.BtnOperate.TabIndex = 0 Me.Controls.Add(Me.BtnOperate)
0
808
by: MTurner | last post by:
Hey guys i'm having some problems creating a program, i have an MDI parent with child windows that are created dynamically (since there is no way for me to know how many are going to be created) however i need to be able to access each one individually after they are created. i've given them names using this childForms(childForm).Name = "SearchForm" & childNumber however i'm unsure how i can dynamically access these forms. so that...
4
1489
by: imranabdulaziz | last post by:
Dear All, I am using asp.net2.0, C#, sql2005 using Visual studio 2005 Let Me explain the scenario I have checkboxlist containg 15 field. Based on no of checked field . I created dropdownlistbox and label dynamically through loop and assign id as dropdownlist + no of iteration. Now my question is how I access these control as when I am accessing one of the control I am getting nullobjectreference error stating “Object reference not set...
0
8402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.