开发者

Placing the same ASP.NET control in different areas of a page

开发者 https://www.devze.com 2022-12-18 23:40 出处:网络
I have some code that I\'ve inherited, and it\'s not the greatest in the world, but it works, with one small exception开发者_StackOverflow社区:

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

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.


you can only do this through JavaScript


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.


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 :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消