I am creating a list (not a gridview control). I use two different databases - I cannot write to one of them. For each row, there will be a checkbox and a textbox that I generated dynamically. I am not using the gridview control for certain formatting issues
- how the form lays, which changes row by row based on data in that row.
Both the checkboxes and textboxes ID's will be established dynamically. I won't have codebehind for each checkbox, but want to use a generic code-behind and pass parameters to it from the checkbox. How is that done?
For example:
Checkbox ID=cbox001 (with elements defined with data)
Checkbox id=cbox002 (with elements defined with data)
I want a single piece of code that runs when I click the checkbox and then reads the defined element values...
Thanks.
-----
Matthew Moran
http://www.KreativeKnowledge.com
http://www.MatthewMoranOnline.com
Since you are working with dynamtic control, so you have to reconstruct them every time Page_OnInit, otherwise, you can't have the postback value/event.
During the Init, you can make a dictionary to link checkbox with textbox when they are created
i.e. MyDict[my_dyn_checkbox] = my_paired_dyn_textbox;
then during the CheckBox_OnSelectedIndexChange
you can use MyDict[CheckBox_WhoFiredEvent] to get the textbox which linked with.
mmonline
Member
24 Points
61 Posts
Dynamically created checkboxes using a single code-behind routine (class)
Feb 29, 2012 04:52 PM|LINK
Not exactly sure how to explain this.
I am creating a list (not a gridview control). I use two different databases - I cannot write to one of them. For each row, there will be a checkbox and a textbox that I generated dynamically. I am not using the gridview control for certain formatting issues - how the form lays, which changes row by row based on data in that row.
Both the checkboxes and textboxes ID's will be established dynamically. I won't have codebehind for each checkbox, but want to use a generic code-behind and pass parameters to it from the checkbox. How is that done?
For example:
Checkbox ID=cbox001 (with elements defined with data)
Checkbox id=cbox002 (with elements defined with data)
I want a single piece of code that runs when I click the checkbox and then reads the defined element values...
Thanks.
Matthew Moran
http://www.KreativeKnowledge.com
http://www.MatthewMoranOnline.com
Cheng Bao
Member
246 Points
145 Posts
Re: Dynamically created checkboxes using a single code-behind routine (class)
Feb 29, 2012 05:58 PM|LINK
Since you are working with dynamtic control, so you have to reconstruct them every time Page_OnInit, otherwise, you can't have the postback value/event.
During the Init, you can make a dictionary to link checkbox with textbox when they are created
i.e. MyDict[my_dyn_checkbox] = my_paired_dyn_textbox;
then during the CheckBox_OnSelectedIndexChange
you can use MyDict[CheckBox_WhoFiredEvent] to get the textbox which linked with.
mmonline
Member
24 Points
61 Posts
Re: Dynamically created checkboxes using a single code-behind routine (class)
Feb 29, 2012 07:40 PM|LINK
I'm unfamilial with creating a dictionary. Looking into it but it sounds like it may work. I will check back in later today or tomorrow.
Thanks.
Matthew Moran
http://www.KreativeKnowledge.com
http://www.MatthewMoranOnline.com