473,732 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2871
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****@discuss ions.microsoft. com> wrote in message
news:15******** *************** ***********@mic rosoft.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****@discuss ions.microsoft. com> wrote in message
news:15******** *************** ***********@mic rosoft.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****@discuss ions.microsoft. com> wrote in message
news:22******** *************** ***********@mic rosoft.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****@discuss ions.microsoft. com> wrote in message
news:15******** *************** ***********@mic rosoft.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****@discuss ions.microsoft. com> wrote in message
news:15******** *************** ***********@mic rosoft.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
565
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 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
1
2576
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 page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g. wucCustomerInfo.ascx,
2
4570
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 easy, but 1) How do I set about dynamically creating user controls (like TextBox, TextArea) --- simply Declare and initialised (new) the user controls?? How do I "place" it graphically on the form. Ideally, I want them to lay out in a table, one...
3
2541
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 controls are not present nor their valves in Request.Form.AllKeys.
9
7039
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 to VB, plus the address bar would show something like this: www.somethinghere?id=3 and if you change number 3 from the address bar to (for example) 34 or 71 you would get different page with the same formatting like I.e: www.somethinghere?id=34...
7
1275
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, look at the UBound of the array (Last control Created) and find the position of the last created control in order to place any new controls next to it. Creating controls in DotNet is different. I can create the controls dynamically but have no...
5
4453
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 survive postback. This seems to be true. However, this seems to make dynamically adding controls rather pointless to me, since if you cannot retrieve the values of the controls when you perform a postback, why add the controls in the firstplace?...
4
2971
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 while and it seems it's not possible because the row that gets added with each click won't get recreated after a post back. After all the reading it seems that any dynamically created controls must be created in the Init event to be recreated after...
0
1313
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 creating these forms, I need to bind controls back to their underlying tables. This has been successful with textboxes, but I am having a lot of difficulty with comboboxes. Setting the datasource to the bindinglist seems to be ok, but I am having...
1
4909
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 set text boxes and labels inside the table rows. I then added a button. All of these are done through code. The problem that i am having is i can get the value from a text box with resides inside the first panel (out side of panel that is...
0
8946
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9235
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9181
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
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, and deploymentwithout 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...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.