473,386 Members | 2,042 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,386 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 1392

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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...

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.