listBox.get_selectedItem() returns null during Transferring

2 posts, 0 answers
  1. Jeff
    Jeff avatar
    10 posts
    Member since:
    Jan 2015

    Posted 12 May 2015 Link to this post

     Hi everybody, 

        So, I'm running into an issues with the list box that is confusing me. I'm working on a page with a two list boxes that I'm using to transfer items back and fourth, really similar to the demo.

    However, when I try to catch the OnClientTransferring event in my javascript, I'm getting a null from get_selectedItem, even though the item is selected? I tested this by adding a handler for OnClientSelectedIndexChanged, and that seems to work fine. What did I miss?

    If it matter's the list boxes are populated programatically based on the input from a 3rd list box.

     Here is my ListBox aspx code.

    <telerik:RadListBox runat="server" ID="RadListBoxAccountSource" Height="300px" Width="300px"
        AllowTransfer="true" TransferToID="RadListBoxAccountDestination" ButtonSettings-AreaWidth="35px">
    </telerik:RadListBox>
    <telerik:RadListBox runat="server" ID="RadListBoxAccountDestination" Height="300px" Width="250px">
    </telerik:RadListBox>

     My JavaScript:

    var listBox;
     
      function pageLoad() {
          listBox = $find("<%= RadListBoxAccountSource.ClientID %>");
      }
     
      function SourceSelectedIndexChange() {
          //This works just fine.
          var selectedItem = listBox.get_selectedItem();
          alert("selected" + selectedItem.get_value());
      }
     
      function transferRight() {
     
          //This returns a list of the items, so I know the list box is populated.
          var Items = listBox.get_items();
     
          //This comes back null
          var selectedItem = listBox.get_selectedItem();
     
          if (selectedItem == null) {
              alert("You need to select a item first.");
              return false;
          }
          else {
              listBox.transferToDestination(selectedItem);
              return false;
          }
      }

     

    Any help or advice would be welcome, I'm not sure what's going on. :/

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 13 May 2015 Link to this post

    Hi Jeff,

    Try to handle some of the ListBox's client events:

    <script>
        var listBox;
     
        function pageLoad() {
            listBox = $find("<%= RadListBoxAccountSource.ClientID %>");
        }
     
        function SourceSelectedIndexChange() {
            //This works just fine.
            var selectedItem = listBox.get_selectedItem();
            alert("selected" + selectedItem.get_value());
        }
     
        function transferRight(sender, args) {
            var item = args.get_item();
        }
    </script>
     
    <telerik:RadListBox runat="server" ID="RadListBoxAccountSource" Height="300px" Width="300px" AllowTransfer="true" TransferToID="RadListBoxAccountDestination"
        ButtonSettings-AreaWidth="35px" OnClientTransferring="transferRight">
    </telerik:RadListBox>
    <telerik:RadListBox runat="server" ID="RadListBoxAccountDestination" Height="300px" Width="250px">
    </telerik:RadListBox>


    Regards,
    Hristo Valyavicharski
    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
Back to Top