listBox.get_items().get_count()... Object does not support this property or method.

3 posts, 0 answers
  1. Mych
    Mych avatar
    18 posts
    Member since:
    Sep 2012

    Posted 13 Feb 2014 Link to this post

    I have the following bit of code that I have taken from Telerik examples... I have a Rad Window with two RadListBoxes. When the user clicks a button the function returnToParent() is called. This should
    a) find the RadListBox2 (which it does)
    b) find out how many items are in the RadListBox (this fails with the error Object does not support this property or method)
    c) if there are no items show error message (yet to check)
    d) iterate through each item and create a string containing each item separated with a semicolon and space (yet to check)
    e) remove the last semicolon and space (yet to check)
    f) close window id string has a value else give error message (yet to check)

    This is my code.... why do I get the error Object does not support this property or method​ at line var x = listBox.get_items().get_count();

    <script type="text/javascript">
      
            function GetRadWindow() {
                var oWindow = null;
                if (window.radWindow) oWindow = window.radWindow;
                else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
                return oWindow;
            }
      
            function returnToParent() {
                //create the argument that will be returned to the parent page
                var oArg = new Object();
      
                //get the ServiceNames name
                var listBox = document.getElementById("RadListBox2");
                listBox = $telerik.toListBox(listBox);
                //error at the next line...
    var x = listBox.get_items().get_count(); 
                if (x < 1) {
                    alert("The listBox is empty.");
                    oArg.Services = "";
                }
                else {
                    for (i = 0; i < x; i++) {
                        oArg.Services += listBox.get_items().get_item(i).value() + "; "
                    }
                    //remove the last semicolon and space
                    oArg.Services = oArg.Services.substring(0, oArg.Services.length - 2);
                }         
                 
                //get a reference to the current RadWindow
                var oWnd = GetRadWindow();
      
                //Close the RadWindow and send the argument to the parent page
                if (oArg.Service) {
                    oWnd.close(oArg);
                }
                else {
                    alert("At least one service must be assigned. If Unknown enter TBC.");
                }
            }
      
        </script>

    Any help appreciated
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Feb 2014 in reply to Mych Link to this post

    Hi Mych,

    Please try the following JavaScript which works fine at my end.

    JavaScript:
    var listBox = $find("<%=RadListBox2.ClientID %>");
    var x = listBox.get_items().get_count();

    Hope this will helps you.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mych
    Mych avatar
    18 posts
    Member since:
    Sep 2012

    Posted 17 Feb 2014 in reply to Shinu Link to this post

    Thanks... This worked fine.
Back to Top