views:

49

answers:

4

I have some code that I've inherited, and it's not the greatest in the world, but it works, with one small exception:

This page is a directory search, it has controls identified by record ID, however there exists a situation where there can be more than one result with the same record ID, thus making .NET barf. I had originally implemented a check that just didn't put the control on the page, if it was already there, but we've been getting negative feedback.

My question is this: Is there a way to put the same control in two places at once, for instance having if a user checks one, the corresponding one checks as well? I'm not terribly well versed in how .NET behaves, but I'll try to provide as much additional context as possible, if needed.

EDIT: Here's the updated code that generates the controls by looping over a datatable of results

Dim cbxSendInfo As CheckBox
Dim strCheckboxID As String = "cbxSendInfo-" & drOrganizer("ID") & "-" & i
Debug.text = Debug.text & "&nbsp;&nbsp;&nbsp;&nbsp;Loading Checkbox (" & strCheckboxID & ")...<br />"

cbxSendInfo = New CheckBox
cbxSendInfo.ID = strCheckboxID
cbxSendInfo.enableViewState = true

And here's the code that finds the controls and builds the contact list:

Dim strCheckboxID As String = "cbxSendInfo-" & drOrganizer("ID") & "-" & i          
Dim cbxSendInfo As CheckBox = Me.tblResults.FindControl(strCheckboxID)

If cbxSendInfo.Checked Then
    alOrganizers.Add(drOrganizer("ID"))
End If

Where drOrganizer("ID") is the record ID, and i is the result record number.

I know this is a terrible way to do this, at least from my background, but like I said, this is inherited code that's been hacked to pieces.

A: 

you can only do this through JavaScript

Adeel
That's what I figured. I'd like to avoid that, if possible. I'm looking at some way of making these identifiers unique such that my FindControl call can still function.
Tim S
A: 

I think I've managed to produce the result I wanted, I have a checkbox for both entries, they don't toggle each other, but that's OK. I was able to append the result row number to the checkbox ID.

Tim S
A: 

You can have duplicate results but if the record ID is the key, then something's wrong. Also, I don't understand what the control ID had to do with the record ID; a code sample might help :-)

IrishChieftain
A: 

Here is a good article on having one checkbox toggle another using javascript:

http://www.dustindiaz.com/check-one-check-all-javascript/

James Campbell