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

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

3 Answers 99 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
luc bonenfant
Top achievements
Rank 1
luc bonenfant asked on 10 Sep 2015, 09:33 PM

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.

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 15 Sep 2015, 01:20 PM
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
0
Lucus
Top achievements
Rank 1
answered on 16 Oct 2015, 06:08 PM

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
    }
}

 

 

 

 

  

0
Ivan Danchev
Telerik team
answered on 20 Oct 2015, 02:45 PM
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
Tags
ListBox
Asked by
luc bonenfant
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Lucus
Top achievements
Rank 1
Share this question
or