ListBox.get_checkedItems() is stale

3 posts, 1 answers
  1. Jeff
    Jeff avatar
    2 posts
    Member since:
    Jul 2016

    Posted 19 Jul Link to this post

    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. Answer
    Ivan Danchev
    Ivan Danchev avatar
    837 posts

    Posted 22 Jul Link to this post

    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.

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeff
    Jeff avatar
    2 posts
    Member since:
    Jul 2016

    Posted 22 Jul in reply to Ivan Danchev Link to this post

    Thank you!
Back to Top