Problem Changing the Checked Property of a dynamic checkbox

S

Scott P.

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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top