JorgeM, thank you for your interest. I did ensure it works when using a button, but it was never finding the cascadingdropdown controls when run during one of the other events I mentioned above.
However, I did manage to get this working as seen here.
Basically, I had to add BehaviorIDs to each of my cascadingdropdown controls and then search for them instead of just the ID. I also had to call my original function using the javascript method pageLoad instead of one of the others. However, since pageLoad is called with any postback, I added a boolean variable to track that so that the function is only called once like so:
var done = false;
function pageLoad(sender, args) {
if (!done) {
myFunction();
done = true;
}
}
For future readers, I would also like to point out that there is an onPopulated event that should work, but wasn't firing for me. You can see how to add that here:
function pageLoad(sender, args)
{
var cdd = $find("behaviorIDofCDD");
cdd.add_populated(onPopulated);
}
function onPopulated()
{
//any function to be called
}
Also, for those looking to manipulate cascading drop downs via javascript in the future, here is how I did it:
var ddl1 = $get('ddl1');
var cddl1 = $find('bID1');
ddl1.set_SelectedValue = "My Value"
if (cddl1 != null) {
cddl1.set_SelectedValue("My Text", "My Value");
}
Please be aware that I am finding the dropdownlist controls using $get and their ID, but the cascadingdropdown controls are being found using $find and their behaviorID.
To set them back to the selection prompt, you can set just the primary cascadingdropdown like this:
ddl1.selectedIndex = 0;
if (cddl1 != null) {
cddl1.set_SelectedValue('', '');
}
I have included all this extra stuff because their is nothing worse that finding the right question in a forum, but not getting a detailed enough answer.