views:

42

answers:

1

I can use jQuery to change the value of a CascadingDropDown, but the event that fires which causes the target control's child dropdown to populate with data never happens:

$("#<%= ddlFromCompetition.ClientID %>").change(function() {
  var fromValue = $("#<%= ddlFromCompetition.ClientID %>").val();
  $("#<%= ddlToCompetition.ClientID %>").val(fromValue); // causes value to change, but child doesn't update
});

To be clear, ddlFromCompetition and ddlToCompetition are not parent/child. It's the child of ddlToCompetition that does not update using the above code. When selecting ddlToCompetition using the mouse, its child dropdown updates as expected.

I've tried calling $("#<%= ddlToCompetition.ClientID %>").change() to try to force the event to fire, but it doesn't work.

A: 

You need the trigger() event

$("#<%= ddlToCompetition.ClientID %>").trigger('change');

JQuery docs: http://api.jquery.com/trigger/

Also, because the first change event handler for ddlFromCompetition fires in the context of ddlFromCompetition, you should be able to change...

var fromValue = $("#<%= ddlFromCompetition.ClientID %>").val();

to...

var fromValue = $(this).val();
Daniel Dyson
The $(this).val() works (the selected value changes) but not trigger('change'). There must be something peculiar about the ASP.NET AJAX CascadingDropDown behavior and which event it fires that causes it to only respond to a manual change event with the mouse.
Mark Richman
Have you tried triggerHandler('change') ? it is worth a try.
Daniel Dyson
Didn't work. I think I somehow need to call CascadingDropDown.raiseSelectionChanged()
Mark Richman
One other thing to try is to change all of the $ symbols to jQuery, i.e. jQuery("#<%= ddlToCompetition.ClientID %>").trigger('change');unless you have already called jQuery.noConflict(); earlier onSee this: http://docs.jquery.com/Using_jQuery_with_Other_Libraries
Daniel Dyson