I am creating multiple rows of controls programmatically; each containing a checkbox and a textbox.
I would like to somehow identify the id of a checkbox so it will know which textbox to delete. What would be the best way to approach this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can make up some sort of naming pattern, for example “cbx-[row num]” for the checkbox and “txt-[row num]” for the text box.
This way you’ll have a bunch of controls named “cbx-1, cbx-2, cbx-3” and matching text boxes named “txt-1, txt-2, txt-3”. Finding a matching “txt-X” for “cbx-X” should be pretty simple.
EDIT: You can use System.Web.UI.FindControl(string) to find a control by it’s id attribute.