Is PostBack required for "x items checked" to display?

3 posts, 1 answers
  1. Kim
    Kim avatar
    15 posts
    Member since:
    Apr 2013

    Posted 03 May 2013 Link to this post

    This is my ComboBox:

    <telerik:RadComboBox ID="cmbLocationDCVL" runat="server" AutoPostBack="false" CheckBoxes="true"
        OnClientBlur="OnClientBlurHandler" Width="150" DropDownWidth="300px">
        <CollapseAnimation Duration="200" Type="OutQuint" />
    </telerik:RadComboBox>

    When I check two items, it should say "2 items checked" in the text field, but it shows nothing until another control forces a postback. the documentation I found does not specify that a postback is required for this functionality. Can someone please confirm that a postback is required? Other than this requirement, a postback isn't necessary, so I was hoping to avoid it.
  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 May 2013 Link to this post

    Hi Kim,

    AutoPostBack is not required for the RadComboBox OnClientBlur event handler to work. Please have a look at the following code I tried which works fine at my end.

    ASPX:
    <telerik:RadComboBox ID="RadComboBox" runat="server" CheckBoxes="true" OnClientBlur="OnClientBlurHandler"
        AutoPostBack="false" Width="150" DropDownWidth="300px">
        <CollapseAnimation Duration="200" Type="OutQuint" />
        <Items>
            <telerik:RadComboBoxItem runat="server" Text="Item 1" />
            <telerik:RadComboBoxItem runat="server" Text="Item 2" />
            <telerik:RadComboBoxItem runat="server" Text="Item 3" />
            <telerik:RadComboBoxItem runat="server" Text="Item 4" />
        </Items>
    </telerik:RadComboBox>

    JavaScript:
    <script type="text/javascript">
        function OnClientBlurHandler(sender, args) {
            var checkedItems = sender.get_checkedItems();
            alert(checkedItems.length + " Items Checked");
        }
    </script>

    Thanks,
    Princy.
  3. Kim
    Kim avatar
    15 posts
    Member since:
    Apr 2013

    Posted 06 May 2013 Link to this post

    Thank you. I hadn't noticed any documentation that I had to do this in JavaScript. This is the script I wrote:
    function OnClientBlurHandler(sender, eventArgs) {
        var checkedItems = sender.get_checkedItems();
        switch (checkedItems.length) {
            case 0:
                sender.set_text("");
                break;
            case 1:
                sender.set_text(sender.get_text());
                break;
            default:
                sender.set_text(checkedItems.length + " items checked");
                break;
        }
    }
Back to Top