Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 16, 2012 05:09 PM by steddyman
Nov 16, 2012 03:16 PM|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?
Nov 16, 2012 03:23 PM|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.
Nov 16, 2012 03:28 PM|LINK
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.
Nov 16, 2012 03:37 PM|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.
Nov 16, 2012 04:18 PM|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:
protected void AddChangeHandlers()
DynamicControl dcCPU = ((DynamicControl)FormView1.FindControl("dcCPU"));
DropDownList dlCPU = ((DropDownList)dcCPU.FieldTemplate.FindControl("DropDownList1"));
DynamicControl dcMemory = ((DynamicControl)FormView1.FindControl("dcMemory"));
DropDownList dlMemory = ((DropDownList)dcMemory.FieldTemplate.FindControl("DropDownList1"));
dlCPU.SelectedIndexChanged +=new EventHandler(CPUMemDropdown_SelectedIndexChanged);
dlMemory.SelectedIndexChanged += new EventHandler(CPUMemDropdown_SelectedIndexChanged);
Nov 16, 2012 04:23 PM|LINK
Hi Steadyman, can you send me your page, my e-mail address is on my blog :)
Nov 16, 2012 04:28 PM|LINK
Just emailed you.
Many thanks for taking a look.
Nov 16, 2012 05:09 PM|LINK
I forgot I needed to set the AutoPostBack property of the DropDownList to True.
Thanks for your help once again.