OnClientTransfering Validate item value exist in destination ListBox

4 posts, 1 answers
  1. Winarsanti Laksmitarani
    Winarsanti  Laksmitarani avatar
    3 posts
    Member since:
    Aug 2008

    Posted 02 Sep 2013 Link to this post

    I need to check item value when transfering if its already exist in destination listbox.
    I came up with this code, but it always failed to get destination items length.
    function validateItemTransfer(sender, args) {
                            debugger;
                            var items = args.get_items();
                            for (var i = 0; i < items.length; i++) {
                                var item = items[i];
     
                                var destinationItems = args.get_destinationListBox().get_items();
                                for (var j = 0; j < destinationItems.length; j++) {
                                    var destinationItem = destinationItems[j];
                                    if (item.get_value() == destinationItem.get_value()) {
                                        args.set_cancel(true);
                                    }
                                }
                            }
                        }

    Pls help,

    Thanks..
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2013 Link to this post

    Hi Winarsanti Laksmitarani,

    To check for duplicate items set the AllowTransferDuplicates property of the RadListBox to true. Please have a look at the following Javascript to get the destination RadListBox length.

    ASPX:
    <telerik:RadListBox ID="RadListBox1" runat="server" TransferToID="RadListBox2" AllowTransfer="true"
        TransferMode="Copy" SelectionMode="Multiple" OnClientTransferred="OnClientTransferred1">
        <Items>
            <telerik:RadListBoxItem runat="server" Text="Item1" Value="1" />
            <telerik:RadListBoxItem runat="server" Text="Item2" Value="2" />
            <telerik:RadListBoxItem runat="server" Text="Item3" Value="1" />
            <telerik:RadListBoxItem runat="server" Text="Item4" Value="2" />
            <telerik:RadListBoxItem runat="server" Text="Item5" Value="3" />
        </Items>
    </telerik:RadListBox>
    <telerik:RadListBox ID="RadListBox2" runat="server">
    </telerik:RadListBox>

    JavaScript:
    <script type="text/javascript">
        function OnClientTransferred1(sender, args) {
            var destinationListbox = $find('<%=RadListBox2.ClientID %>');
            var count = destinationListbox.get_items().get_count();
            alert("Destination listbox count :" + count);
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Winarsanti Laksmitarani
    Winarsanti  Laksmitarani avatar
    3 posts
    Member since:
    Aug 2008

    Posted 03 Sep 2013 Link to this post

    Hi Shinu,

    Thanks for your solution, i though i could use .length function to get the size, i don't know it should use get_count() method instead.
    Btw how do you know all API inside getDestinationListBox() ?


    Best regards
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Sep 2013 Link to this post

    Hi Winarsanti Laksmitarani,

    You will get the Client Side API for RadListBox from this documentation.

    Thanks,
    Shinu.
Back to Top