473,320 Members | 1,953 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,320 software developers and data experts.

Read values of dynamically generated checkboxes during postback

I've got a page that has a Panel object that I am dynamically adding
CheckBox controls to. The number of CheckBox controls and the name of each
control is based on a database query. I would like to know how I can query
for all the CheckBox controls on the page during postback and check their
checked attribute without using the name of each checkbox. I want to do
this in a generic way so that I don't have to requery the db or save the
names of all the CheckBox controls somewhere to use during postback. For
CheckBox controls that are placed on the page during design time, this is
easy because I know the name. I'm just not sure how to do this for the
particular scenario I am describing here.

Thanks!
Nov 19 '05 #1
4 2391
In the Panel codebehind or in whatever Control you are adding the
checkboxes *directly* to just iterate through the Control collection by
number. The index will correspond to exactly what order you added them
in, so you'll have to know that.

foreach(Control control in this.Controls)
{
if(control is CheckBox)
{
CheckBox checkBox = (CheckBox) control;
// here is your checkbox
}
}

something liket this anyway

Nov 19 '05 #2
I thought I could do this to, but it doesn't seem to be working. Maybe my
approach is wrong. I am doing exactly this in my page load method (in the
area of code that only executes if it IS a postback). The Controls
collection for my panel, that I added the checkboxes to in page load (not in
a post back), is empty. I thought the viewstate would rebuild the controls
and the panel's Controls collection would have many controls in it. Is this
the case because I'm dynamically adding CheckBox controls to the panel?

Thanks.

<sa*************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
In the Panel codebehind or in whatever Control you are adding the
checkboxes *directly* to just iterate through the Control collection by
number. The index will correspond to exactly what order you added them
in, so you'll have to know that.

foreach(Control control in this.Controls)
{
if(control is CheckBox)
{
CheckBox checkBox = (CheckBox) control;
// here is your checkbox
}
}

something liket this anyway

Nov 19 '05 #3
>>> The Controls collection for my panel, that I added the checkboxes
to in page load (not in a post back)
Haha. Anyway, you need to add the checkboxes *all* the time, not just
if not postback.

Nov 19 '05 #4
Oh yes. Even if you do what I said, they won't have the right
'checked' values in them until the button click postback event happens.
Add them in the OnInit method and then you can get the right state in
PageLoad.

Nov 19 '05 #5

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

Similar topics

2
by: Alan Lambert | last post by:
I have a web page that contains, amongst other things, a DropDownList called drpProjectCodes) and a Panel (called pnlStatus) which contains six Checkboxes. drpProjectCodes contains a list of...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
2
by: david | last post by:
I have no idea how to get the IDs of dynamically genrated CheckBoxes and the events of CheckedChange. I have dynamically generated array of CheckBoxes, checkboxes,which dynamically display in a...
2
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the...
0
by: deathtospam | last post by:
A few weeks ago, I created a Classic ASP page that connects to a machine with SQL Server installed on it, prompts the user to select a database on that server, then lists all of user-created stored...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
0
by: 1388-2/HB | last post by:
I have a page with a significant number of dynamically created radio buttons, checkboxes and textboxes. When a user is presented with this form and subsequently fills a bunch of stuff out, when...
1
by: noneya22 | last post by:
I have an accordion control with a dynamically generated asp.net checkbox server-side control in each accordion pane. On postback I loop through all of the controls on the page, and I never find...
0
by: rvdnieuwenhuizen | last post by:
Hi, The problem I cannot seem to solve: I have a page with a button control. In the On_Click eventhandler I dynamically add one TextBox each time the button is clicked. I add the textboxes to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll 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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.