473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamically creating array of controls

Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got the
following error while I tried to assign value to ID property of dynamically
created textbox. (look at my code please )

Error: “ Object reference is not set to an instance of Object”

totalRows – int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox[i].ID = “myTextbox”; //Getting error here

}

Thanks,
Nov 22 '05 #1
6 2842
an id is a unique identifier, it seems you are passing the same value to all
of the controls.. try this..
For (int i=0; i < totalRows; i++)
{

txbox[i].ID = “myTextbox” + i;

}

"Bhavin" wrote:
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got the
following error while I tried to assign value to ID property of dynamically
created textbox. (look at my code please )

Error: “ Object reference is not set to an instance of Object”

totalRows – int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox[i].ID = “myTextbox”; //Getting error here

}

Thanks,

Nov 22 '05 #2
Do you know how can I capture values from dynamically created controls?

"[Alan Flores]" wrote:
an id is a unique identifier, it seems you are passing the same value to all
of the controls.. try this..
For (int i=0; i < totalRows; i++)
{

txbox[i].ID = “myTextbox” + i;

}

"Bhavin" wrote:
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got the
following error while I tried to assign value to ID property of dynamically
created textbox. (look at my code please )

Error: “ Object reference is not set to an instance of Object”

totalRows – int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox[i].ID = “myTextbox”; //Getting error here

}

Thanks,

Nov 22 '05 #3
When you create an array of objects, the objects inside it are NOT
initialized ! In other owrd, it's an array of null values mate ... change
your code to this:

Textbox[] txbox = new Textbox [totalRows];

for(int i=0; i < totalRows; i++){
txbox[i] = new Textbox();
txbox[i].ID = "myTextbox"+i;
}

Angel
O:]


"Bhavin" <Bh****@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of dynamically created textbox. (look at my code please )

Error: " Object reference is not set to an instance of Object"

totalRows - int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox[i].ID = "myTextbox"; //Getting error here

}

Thanks,

Nov 22 '05 #4

Thanks a lot Angel. It worked(But next problem)

Textbox[] txbox = new Textbox [totalRows];

for(int i=0; i < totalRows; i++){
txbox[i] = new Textbox();
txbox[i].ID = "myTextbox"+i;
}

I used above code in my page_load event. It worked. But once all dynamic
empty textboxes got created I entered values in them. Now I want to capture
those values using dynamic IDs of textboxes but those IDs no longer available
after page_load event. I would like to capture all values from textboxes to
INSERT data in SQL table.

"Angelos Karantzalis" wrote:
When you create an array of objects, the objects inside it are NOT
initialized ! In other owrd, it's an array of null values mate ... change
your code to this:

Textbox[] txbox = new Textbox [totalRows];

for(int i=0; i < totalRows; i++){
txbox[i] = new Textbox();
txbox[i].ID = "myTextbox"+i;
}

Angel
O:]


"Bhavin" <Bh****@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got

the
following error while I tried to assign value to ID property of

dynamically
created textbox. (look at my code please )

Error: " Object reference is not set to an instance of Object"

totalRows - int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox[i].ID = "myTextbox"; //Getting error here

}

Thanks,


Nov 22 '05 #5
You could just store those controls in a member variable in your page class,
and check on them, getting their .Text property.

.... or, when you create them, you could add an event handler for their
OnChange event, adn get the values that way

.... or, you could even loop inside the page's controls collection and find
them through there !

... or I could just keep writing. I think the first or second suggestion
will work fine :]

Angel
O:]
"Bhavin" <Bh****@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...

Thanks a lot Angel. It worked(But next problem)

Textbox[] txbox = new Textbox [totalRows];

for(int i=0; i < totalRows; i++){
txbox[i] = new Textbox();
txbox[i].ID = "myTextbox"+i;
}

I used above code in my page_load event. It worked. But once all dynamic
empty textboxes got created I entered values in them. Now I want to capture those values using dynamic IDs of textboxes but those IDs no longer available after page_load event. I would like to capture all values from textboxes to INSERT data in SQL table.

"Angelos Karantzalis" wrote:
When you create an array of objects, the objects inside it are NOT
initialized ! In other owrd, it's an array of null values mate ... change your code to this:

Textbox[] txbox = new Textbox [totalRows];

for(int i=0; i < totalRows; i++){
txbox[i] = new Textbox();
txbox[i].ID = "myTextbox"+i;
}

Angel
O:]


"Bhavin" <Bh****@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got
the
following error while I tried to assign value to ID property of

dynamically
created textbox. (look at my code please )

Error: " Object reference is not set to an instance of Object"

totalRows - int variable which varies with number of records in SQL

table
Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox[i].ID = "myTextbox"; //Getting error here

}

Thanks,


Nov 22 '05 #6
Dan
Angelos - Can you translate into vb.net? - Can you direct me to a newsgroup
that might if not?

Thanks

Dan

"Angelos Karantzalis" wrote:
When you create an array of objects, the objects inside it are NOT
initialized ! In other owrd, it's an array of null values mate ... change
your code to this:

Textbox[] txbox = new Textbox [totalRows];

for(int i=0; i < totalRows; i++){
txbox[i] = new Textbox();
txbox[i].ID = "myTextbox"+i;
}

Angel
O:]


"Bhavin" <Bh****@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
Anybody quickly replies it, would be a great help!

I try to create dynamic array of textboxes control in ASP.NET(C#). I got

the
following error while I tried to assign value to ID property of

dynamically
created textbox. (look at my code please )

Error: " Object reference is not set to an instance of Object"

totalRows - int variable which varies with number of records in SQL table

Textbox[]txbox = new Textbox [totalRows];

For (int i=0; i < totalRows; i++)
{

txbox[i].ID = "myTextbox"; //Getting error here

}

Thanks,


Nov 22 '05 #7

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

Similar topics

6
by: Bhavin | last post by:
Anybody quickly replies it, would be a great help! I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
2
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is...
3
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
7
by: Lou | last post by:
I have a menu item that creates a new command button. Each time I create a new command button I need to position it to the left of the last created button. In VB6 I could create a control array,...
5
by: Nathan Sokalski | last post by:
I have a custom control that I wrote (I inherit from System.Web.UI.WebControls.CompositeControl). I dynamically add this control to my Page, but I was told that dynamically added controls do not...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
0
by: theleshie | last post by:
Hi, I am creating an application which dynamically creates forms depending on the information held in a dataset (which also includes the data the application itself uses). As part of dynamically...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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 projectplanning, coding, testing,...

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.