Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
40
WebDropDown - PostBack
posted

Hi,

I have a WebDropDown (v11.1, .Net 3.5) and have the "ALL" as the first item that helps in selecting all the items.

I have hooked up the ClientEvents "SelectionChanged" and "ValueChanged" to handle the "ALL" selection and it works fine. Only "ALL" is selected when all the items are selected.

But when i click a button that performs a postback, the WebDropDown has all items including the "ALL". Can this be overcome or am i missing something?

Parents
No Data
Reply
  • 40
    Verified Answer
    posted

    Hi,

    I found the answer myself but not sure if efficient.

    I hooked the following ClientEvents "SelectionChanged", "DropDownClosed", "DropDownOpened". In DropDownOpened, I make all items to be selected if "ALL" is selected. In DropDownClosed, I make all items unselected EXCEPT "ALL". So, even in Postback the only "ALL" is displayed.

    In case if it helps someone., here goes the code

    function wdd_dropDownOpened(sender, eventArgs) {
        var items = sender.get_items();
        if (items.getItem(0).get_selected() == true && items.getItem(0).get_text().toUpperCase() == 'ALL') {
            for (i = 1; i < items.getLength(); i++) {
                var item = items.getItem(i);
                item.select();
            }
        }


    } // -->
    function wdd_dropDownClosed(sender, eventArgs) {
        var activeIndex = sender.get_activeItemIndex();
        var items = sender.get_items();
        if (activeIndex == 0 && items.getItem(0).get_selected() == true) {
            sender.set_currentValue("ALL", true);
            for (i = 1; i < items.getLength(); i++) {
                var item = items.getItem(i);
                item.unselect();
            }
        }

    }
    function selectedIndexChanged(sender, eventArgs) {
        var activeIndex = sender.get_activeItemIndex();
        var items = sender.get_items();
        if (activeIndex == 0 && items.getItem(0).get_selected() == true && items.getItem(0).get_text().toUpperCase() == 'ALL') {
            for (i = 1; i < items.getLength(); i++) {
                var item = items.getItem(i);
                item.select();
            }
        }
        else if (activeIndex == 0 && items.getItem(0).get_selected() == false && items.getItem(0).get_text().toUpperCase() == 'ALL') {
            for (i = 1; i < items.getLength(); i++) {
                var item = items.getItem(i);
                item.unselect();
            }
        }
        else if (activeIndex != 0) {
            if (items.getItem(activeIndex).get_selected() == false) {
                items.getItem(0).unselect();
            }
        }
    }

    Ok, i have 2 questions now..

    1. Is the above method efficient? Any other workarounds?

    2. I have around 15 ASPX pages, can I create a Custom control to include the above Javscript to avoid repetitive code? Please suggest.

     

Children
No Data