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

Problem Changing the Checked Property of a dynamic checkbox

I'm creating an app using ASP .NET (my second app so bear with me here) that
basically builds a PDF file based on a bunch of user selections. I have a
page which displays a series of checkboxs using the checkbox object. These
are all created on-the-fly using the following code:

While dtrSelect.Read
Dim DocumentRow As New TableRow
Dim DocumentCell As New TableCell
Dim DocumentCell1 As New TableCell
Dim chkDocument As CheckBox

DocumentCell1.Text = ""
DocumentRow.Cells.Add(DocumentCell1)
chkDocument = New CheckBox
chkDocument.ID = "Check" & dtrSelect("DocumentID") & "|Parent" &
Record("DocumentID")
chkDocument.Text = " " & dtrSelect("DocumentDescription")
DocumentCell.Controls.Add(chkDocument)
DocumentRow.Cells.Add(DocumentCell)
tblChooseTabs.Rows.Add(DocumentRow)
End While

These checkboxs are in groups, and each group has a parent (which basically
relates each individual PDF file to a category). On this particular page,
the parent is simply displayed as it's text description, and then it's
children are listed underneath it with nifty little checkboxes for the user
to tick off their selections.

My challenge is to add a "Select All/Deselect All" button to each section of
this page. In this particular case, there are 7 parents with at least 2
children in each section (some have 20 children). I am adding a button
underneath the title for each section as follows:
'Add the Select/Deselect All button to this section
Dim SelectAllRow As New TableRow
Dim SelectAllCell As New TableCell
Dim cmdSelectAll As New Button

SelectAllCell.ColumnSpan = "2"
SelectAllCell.CssClass = "selectAll"

cmdSelectAll = New Button
cmdSelectAll.ID = "SelectAll" & Record("DocumentID")
cmdSelectAll.Text = "Select Entire Group"

SelectAllCell.Controls.Add(cmdSelectAll)
SelectAllRow.Cells.Add(SelectAllCell)

tblChooseTabs.Rows.Add(SelectAllRow)

So far this all works fine and dandy. The problem occurs when I actually
click the buttons I've added dynamically to this form. It does do a
PostBack as expected, but for some reason, I can't seem to get the
checkboxes to cooperate and actually check themselves off. I've done some
research and it appears that any dynamically created control must be
re-created at PostBack before any actions can be taken upon it. So I added
a new test to my PostBack script to just run as normal upon PostBack, with
one exception. At the very end (last line actually) it calls a sub-routine
I wrote that loops through all the controls on the page and attempts to
check off the proper ones. Only it refuses to work for me. Might be
something simple, might be a rookie mistake...who knows. That's why I'm
asking here ;-)

Here's my sub-routine:

Public Sub ModifyControls(ByVal objControl)
Dim objChild As System.Web.UI.Control

For Each objChild In objControl.Controls
' Perform whatever processing you want to execute on the child
control(here)
If InStr(objChild.ID, "Parent" & intSelectAll) > 0 Then
CType(objChild, CheckBox).Checked = True
End If

' Call this method to recurse through all the nested Controls
ModifyControls(objChild)
Next
End Sub

I have made the full source for this page available at:
http://www.scpsoftware.net/dotnet/ChooseTabs.txt as the code I posted here
is just a very small portion and the problem might lie elsewhere.

Any help you guys and/or gals can offer would be MUCH appreciated. I have
very little hair left after I pulled out a bunch of it this afternoon. I
tried @ 5 different methods I found via Google and the Newsgroups today and
all seem to end in the same manner.

Static Versionof the actual page is available here:
http://www.scpsoftware.net/dotnet/ChooseTabs.htm

Thanks in Advance!

Scott Pouliot
sp******@scpsoftware.net
Nov 18 '05 #1
0 1386

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

Similar topics

0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
0
by: Scott P. | last post by:
I'm creating an app using ASP .NET (my second app so bear with me here) that basically builds a PDF file based on a bunch of user selections. I have a page which displays a series of checkboxs...
0
by: Mike Hofer | last post by:
Hi everyone. I could really use some help. First, the backstory: ===================== I *really* need a 3-state checkbox for my ASP.NET application. Specifically, I need one that lets me set...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
0
by: gwilliam | last post by:
Problem with checkboxes in webpages. I am trying to re-set the values of dinamically created checkboxes in a web page, but no matter what I try the "Checked" property is not set correctly. A...
6
by: Brandon McCombs | last post by:
Hello, I have a Form that contains some configuration information. One of the settings is for SSL. There is a checkbox that I want to check to make 2 textboxes un-editable so that a user can...
0
by: =?Utf-8?B?SWRlcm9ja3M=?= | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and I...
1
by: iderocks | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and when I...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
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: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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...

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.