CheckedItems.Count returns 0 if enabled = false when loading page

4 posts, 0 answers
  1. luc bonenfant
    luc bonenfant avatar
    53 posts
    Member since:
    Sep 2007

    Posted 10 Sep 2015 Link to this post

    Hello, 

    I i have a Rad​ListBox with checkboxes named "myCkList".
    Im my case, i check some boxes and i observe CheckedItems in server side after clicking button. I'm suprised because myCkList.CheckedItems.Count = 0 ...

     In fact, it's because i added property Enabled=false to myCkList in ​aspx page (of course i enable it client side before clicking checkboxes) !

    Is it a normal behavior in asp.net ?

    I can work with Enabled=true and set_enabled(false) from pageLoad..., no problem.

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    835 posts

    Posted 15 Sep 2015 Link to this post

    Hello,

    We tested your scenario and we can confirm that the observed behavior is a bug. It is now logged and we will fix it in one of our future releases. Please accept our apologies for any inconvenience it might have caused you.

    You can track the bug's progress on our feedback portal and vote/rate it if you like.

    Until the bug is fixed we recommend disabling/enabling the RadListBox on the client and not in the markup or code behind.

    As a token of gratitude for reporting this issue I updated your Telerik Points.

    Regards,
    Ivan Danchev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lucus
    Lucus avatar
    1 posts
    Member since:
    Sep 2015

    Posted 16 Oct 2015 in reply to Ivan Danchev Link to this post

    I am having this same issue but I can't seem to get the checked items even if I set the listbox disabled in the pageload client side

      

    function pageLoad() {
       $find('<%= rlbMyList.ClientID %>').set_enabled(false);
    }
      
     function ToggleListBox(button, args) {
            var listBox = $find('<%= rlbMyList.ClientID %>');
            var state = args.get_currentToggleState().get_value();
      
            listBox.set_enabled(state);
      
            var items = listBox.get_items();
            listBox.trackChanges();
            items.forEach(function (item) {
                if (state === "True") {
                    item.enable();
                } else {
                    item.disable();
                    item.uncheck();
                }
            });
      
            listBox.commitChanges();
        }

    the control

    <telerik:RadButton runat="server" ID="rbEditMylist" ToggleType="CustomToggle" AutoPostBack="False" OnClientToggleStateChanged="ToggleListBox">
          <ToggleStates>
               <telerik:RadButtonToggleState Text="Formats Unchanged" Value="False"               PrimaryIconCssClass="rbToggleCheckbox" Selected="True">
              </telerik:RadButtonToggleState>
              <telerik:RadButtonToggleState Text="Formats Edited" Value="True" PrimaryIconCssClass="rbToggleCheckboxChecked" CssClass="rbSkinnedButtonChecked">
              </telerik:RadButtonToggleState>
           </ToggleStates>
    </telerik:RadButton>
    <telerik:RadListBox ID="rlbMyList" runat="server" CheckBoxes="True" Width="100%"></telerik:RadListBox>

    and in the code behind

    protected void OnUpdateClicked(object sender, EventArgs e)
    {
       if (Convert.ToBoolean(rbEditAcceptableFormat.SelectedToggleState.Value))
        {
           var item = rlbMyList.CheckedItems; // this is always 0 items
        }
    }

     

     

     

     

      

  5. Ivan Danchev
    Admin
    Ivan Danchev avatar
    835 posts

    Posted 20 Oct 2015 Link to this post

    Hello,

    Your case is different. The CheckedItems property returns 0 on the server because you are passing a string to the set_enabled() method in the ToggleListBox handler, but it expects a Boolean type. The get_value() method returns a string so the "state" variable holds the string "True" as its value instead of the Boolean true. With the modification posted below I was able to get the count of the checked items on the server:
    function ToggleListBox(button, args) {
        var listBox = $find('<%= rlbMyList.ClientID %>');
        var state = args.get_currentToggleState().get_value();
     
        //listBox.set_enabled(state);
     
        if (state == "True") {
            listBox.set_enabled(true);
        }
        else {
            listBox.set_enabled(false);
        }
     
        var items = listBox.get_items();
        listBox.trackChanges();
        items.forEach(function (item) {
            if (state === "True") {
                item.enable();
            } else {
                item.disable();
                item.uncheck();
            }
        });
     
        listBox.commitChanges();
    }

    Regards,
    Ivan Danchev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top