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

listBox.get_selectedItem() returns null during Transferring

1 Answer 233 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 12 May 2015, 05:02 PM

 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. :/

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 13 May 2015, 11:32 AM
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
Tags
ListBox
Asked by
Jeff
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or