I have a form with a mix of DynamicControls bound to LINQ for SQL and standard controls. I need to trigger an event handler when the DropDown control created by the DynamicControl changes value, so I can update a Label field with a calculated value.
I can't see any of the standard events for these controls so how could I hook into the control value changing?
Hi steddyman, there are no standard events for this but if you fine the DynamicControl and then ectract the field template you can then cast the DataControl to DropDownList and then add an event handler to that's selection changed event.
See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.
What would be the best place for me to insert that event handler into within the Standard page flow? I've only ever wired up events declaratively, not from code for controls.
It doesn't seem to be working for me for some reason. I can't seem to register the handlers in Page_Init even after the RegisterControl command is issued, because it reports that the DropDownList1 control is not found.
I can register them in Page_Load, but when I place breakpoints in the handlers, they are never being called when I change the drop downs. This is the code I am using:
Member
15 Points
82 Posts
Tracking DynamicControl change events
Nov 16, 2012 11:16 AM|steddyman|LINK
I have a form with a mix of DynamicControls bound to LINQ for SQL and standard controls. I need to trigger an event handler when the DropDown control created by the DynamicControl changes value, so I can update a Label field with a calculated value.
I can't see any of the standard events for these controls so how could I hook into the control value changing?
Thanks
All-Star
17916 Points
5681 Posts
MVP
Re: Tracking DynamicControl change events
Nov 16, 2012 11:23 AM|sjnaughton|LINK
Hi steddyman, there are no standard events for this but if you fine the DynamicControl and then ectract the field template you can then cast the DataControl to DropDownList and then add an event handler to that's selection changed event.
Always seeking an elegant solution.
Member
15 Points
82 Posts
Re: Tracking DynamicControl change events
Nov 16, 2012 11:28 AM|steddyman|LINK
Hi
Thanks for the quick response. That makes sense.
What would be the best place for me to insert that event handler into within the Standard page flow? I've only ever wired up events declaratively, not from code for controls.
All-Star
17916 Points
5681 Posts
MVP
Re: Tracking DynamicControl change events
Nov 16, 2012 11:37 AM|sjnaughton|LINK
I woudl do that in either Page_Init or Page_Load as any later than that and I don;t seem to recive the events most of the time.
Always seeking an elegant solution.
Member
15 Points
82 Posts
Re: Tracking DynamicControl change events
Nov 16, 2012 12:18 PM|steddyman|LINK
It doesn't seem to be working for me for some reason. I can't seem to register the handlers in Page_Init even after the RegisterControl command is issued, because it reports that the DropDownList1 control is not found.
I can register them in Page_Load, but when I place breakpoints in the handlers, they are never being called when I change the drop downs. This is the code I am using:
All-Star
17916 Points
5681 Posts
MVP
Re: Tracking DynamicControl change events
Nov 16, 2012 12:23 PM|sjnaughton|LINK
Hi Steadyman, can you send me your page, my e-mail address is on my blog :)
Always seeking an elegant solution.
Member
15 Points
82 Posts
Re: Tracking DynamicControl change events
Nov 16, 2012 12:28 PM|steddyman|LINK
Just emailed you.
Many thanks for taking a look.
Member
15 Points
82 Posts
Re: Tracking DynamicControl change events
Nov 16, 2012 01:09 PM|steddyman|LINK
Fixed it!
I forgot I needed to set the AutoPostBack property of the DropDownList to True.
Thanks for your help once again.