This is a migrated thread and some comments may be shown as answers.

ListBox.get_checkedItems() is stale

2 Answers 208 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 19 Jul 2016, 11:17 PM

So, I have scoured the NET and the ListBox release notes and cannot find anyone else having this problem so I am hoping this will be an easy fix by a Telerik Guru. I am using,

  • Telerik UI for ASP.NET AJAX ver. 2014.3.1209.45
  • browser: Chrome

Behavior: Upon initial load, I write values from the server side to the new control. Upon checking or unchecking, my JavaScript function fires, but the ListBox's get_checkedItems() method returns the items that are checked "before" the "OnClientItemChecking" event fires. I would expect to get the items of the ListBox after I check or uncheck items, in other words, the current state of the ListBox. Anyone have any ideas?

<telerik:RadListBox ID="CMListBox" runat="server" RenderMode="Lightweight" SelectionMode="Multiple"CheckBoxes="true" Width="300px" OnClientItemChecking="CMListBox_ItemChecking" Height="100px">                                <Items></Items></telerik:RadListBox>

function CMListBox_ItemChecking(sender,args)
{
  var Radlb = $find("<%= CMListBox.ClientID %>");
  var txt = "";
  var labelStr = "";
  var iter = Radlb.get_checkedItems().length;
  for (var i = 0; i < iter ; i++)
  {
     txt = Radlb.get_checkedItems()[i].get_text();
     labelStr += txt + "<br>";
  }
  if (labelStr != ""){
     labelStr = labelStr.substring(0, labelStr.length - 4);
  }
  else {
     labelStr = "None";
  }
  var s = document.getElementById("CommManagerID");
  s.innerHTML = labelStr;
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 22 Jul 2016, 11:56 AM
Hello Jeff,

As explained in the documentation the newly checked/unchecked items are not available in the checked items collection in the OnClientItemChecking event handler, because this event fires prior to the items being actually checked/unchecked. One of the purposes of this event is that it can be cancelled and thus prevent the action, so if you want to get the current state after the items are checked/unchecked you can use a different event: OnClientItemChecked.

Regards,
Ivan Danchev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Jeff
Top achievements
Rank 1
answered on 22 Jul 2016, 04:56 PM
Thank you!
Tags
ListBox
Asked by
Jeff
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or