Approved
Last Updated: 22 Apr 2019 13:10 by ADMIN
Devora
Created on: 19 Apr 2019 11:06
Category: ListBox
Type: Bug Report
0
Selected index is not persisted after canceling OnClientSelectedIndexChanging event
I have a few instances where I need OnClientSelectedIndexChanging inorder to stop the listbox selectedIndexChanged event from posting back in certain cases. In those cases I stop it from posting back by setting the e.set_cancel(true);

function CheckForListBoxReorder_OnClientEvent(sender, e) {
    if (ListboxReordered()) {
        alert('Please save changes to the bus order.');
        e.set_cancel(true);
    }
}

This works very nicely, but I'm getting many errors because although it looks like it's still selected to the proper row in the listbox the selectedIndex is now -1.
1 comment
ADMIN
Peter Milchev
Posted on: 19 Apr 2019 11:08
Hello Devora,

Thank you for reporting this issue, as a temporary workaround, the following approach can be used: 

<script>
    function OnClientSelectedIndexChanging(sender, args) {
        var chkb = $find("<%= RadCheckBox1.ClientID %>");
  
        if (chkb.get_checked()) {
            args.set_cancel(true);
            var selectedItem = sender.get_selectedItem();
            if (selectedItem) {
                sender._registerSelectedIndex(selectedItem.get_index());
            }
        }
    }
</script>

Regards,
Peter Milchev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.