473,322 Members | 1,703 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,322 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 2838
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.