Showing posts with label weird. Show all posts
Showing posts with label weird. Show all posts

Wednesday, March 21, 2012

CascadingDropDown question

I have weird problem with CascadingDropDown. I have user control with two dropDowns. If I get into this page through Select Class -> Select Category pages I set

CascadingDropDown1.Enabled =false (and so on for all of them)
and use query string to populate DDLs and set selected value. Or I can directly get into this page and use CascadingDropDown since I don't have query string.

But it doesn't work this way. When I get into this page through Select Class -> Select Category pages everything is fine, but after first postback ddl's datasources are empty.

If I completely remove CascadingDropDown definition from code - it works OK.

Any idea why this happens? Not sure, probably I'm missing something or it's CascadingDropDown bug.

Thanks.

Vladimir.

Hi Vladimir,

Can you elaborate what do you mean by "Select Class -> Select Category pages" ?

I don't quite understand your problem.


Thanks very much for the replay.

I mean that I have on the page two DropDownLists. First I select Class then by this Class i can select Category. After I select Category I'm able to populate GridView.

On this page I can get either through direct link (in this case I don't have data for Class and Category and wanted to use CascadingDropDown) or I can go first on the page SelectClass. Then on the page SelectCategory which will move to the page where I'll have Class and Category already selected and available in the query string in the url address.

This is basically what I wanted.

CascadingDropDown Issue?

I'm having this weird problem with the CascadingDropDown:
I'm using three DropDown controls in cascade, and a CommandButton to fill a gridview. When the last control fills up, and I press my CommandButton, I can't see the value of the last DropDown. I mean that the value arrives empty, but the other two have the right value.
One thing that I've noted is that this happend when the DropDown is populated with only one item.

Any help or guidance would be apreciated.Debugging a little more I've foud that the problem is the item marked as default in the DropDown. If I select the items manually, it works fine, but when I left untouched the dinamically populated DropDown's (with the items marked as default shown in them), then I recive an empty string as value.

Anyone has had this problem?

Regards

Thanks for the report. I've opened work item 2218 to track this. I believe I have a fix you can try.

In CascadingDropDownBehavior.js, change:

// if we didn't match the selected value, and we found a default
// item, select that one.
//
if (!matchedSelectedValue && defaultIndex != -1) {
e.options[defaultIndex].selected = true;
this.set_SelectedValue(e.options[defaultIndex].value);
}
if
(!inInit && !matchedSelectedValue && !gettingList) {
this.set_SelectedValue('');
}

To:

// if we didn't match the selected value, and we found a default
// item, select that one.
//
if (!matchedSelectedValue && defaultIndex != -1) {
e.options[defaultIndex].selected = true;
this.set_SelectedValue(e.options[defaultIndex].value);
} else if (!inInit && !matchedSelectedValue && !gettingList) {
this.set_SelectedValue('');
}

That fixes the problem for me in my simple scenario. Please let me know if it works for you, too.


I didn't realize it was so easy to change! Thank you a lot, now it works as expected.Big Smile

I've fixed this for the next release of the Toolkit as change 3778 in CodePlex:

CascadingDropDown's handling of default values for drop-downs that the user didn't interact with was such that an empty value would be seen on the server for the relevant .SelectedValue on postback. Fix that problem and add an automated test case to cover the scenario.