Obtain a reference to combo box

8 posts, 1 answers
  1. sara
    sara avatar
    31 posts
    Member since:
    May 2007

    Posted 22 Apr 2008 Link to this post

    I am trying to obtain a reference to a combo box after the page loads.

    I've tried (where rcbRegion is the combo box):
    var ddl = <%= rcbRegion.ClientID %>;

    var ddl = $find(<%= rcbRegion.ClientID %>);

    var ddl = document.getElementById('<%= rcbRegion.ClientID %>);

    On the first and the last, I can do ddl.id and get the appropriate id, but when I try to do ddl.get_value(); I get an error saying "Object doesn't support this property or method."  I get the same error when trying to access any of the methods the combo box supports.

    The second returns null.

    What am I doing wrong, and which of these are supposed to work?
  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 23 Apr 2008 Link to this post

    Hi sara,

    The proper syntax is the following:

    var ddl = $find("<%= rcbRegion.ClientID %>"); 

    Note the quotes.

    Here you can find more information: Client-side basics

    I hope this helps.

    Sincerely yours,
    Veskoni
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. AdamL
    AdamL avatar
    41 posts
    Member since:
    Aug 2006

    Posted 11 May 2008 Link to this post

    I am attempting this same thing but when I use the code:

    var ddl = $find("<%= rcbRegion.ClientID %>"); 

    I get the following error:

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Per the advice of another site, I changed the <%= to <%#.  The page does load but, the call to $find returns null.

    I am attempting to base the values of one combo box off the selection of another.  Following your examples, I am attempting to get a handle to the combo box and call "requestItems(sender.get_text(),false);"  I have altered the ItemRequested event of the combo to use the text but I cannot seem to get a handle to the combo box client side.  Any help or alternative solution is appreciated.

    - Adam
  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 12 May 2008 Link to this post

    Hello lindsaad,

    Please check if your javascript code resides in the <head> section of the page. If yes - you need to move it outside of the <head> tag.

    <head runat=a?servera?> 
    </head> 
    <body> 
       <script> 
       var controlClientObject = $find("<%= RadComboBox1.ClientID %>"); 
       ... 
       </script> 
    ... 
    </body> 

    Also, you might find this article helpful:
    http://www.telerik.com/help/aspnet-ajax/ajxradscriptblockradcodeblock.html


    Best wishes,
    Veskoni
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. AdamL
    AdamL avatar
    41 posts
    Member since:
    Aug 2006

    Posted 12 May 2008 Link to this post

    The code is not in the <head>.  However, it is on a page that has a MasterPage so it is located withing the Content Placeholder. 

    I was able to resolve this issue by using the Telerik.Web.UI.RadComboBox.ComboBoxes[] array.  As an interesting note:  If you have a combobox with the OnClientLoad event firing some code, any comboboxes rendered after the one with the OnClientLoad do not get added to the ComboBoxes[] array.  I ran into this issue where I had 5 comboboxes on the form; the third one had a OnClientLoad event.  Becuase of this only the first three comboboxes were in the array.  When I removed the OnCLientLoad event, all 5 were in the array.

    - Adam
  7. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 13 May 2008 Link to this post

    Hi Adam,

    I am glad that you resolved the problem.

    About the other problem you mentioned - this is true only if you count the number of items in the array during the OnClientLoad event handler of one of the comboboxes - since the other combos are still not initialized on the page. You can subscribe to the pageLoad() event (when all controls are initialized) and check that the number of combos in the array is correct.

    Sincerely yours,
    Veskoni
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Mark
    Mark avatar
    1 posts
    Member since:
    Oct 2008

    Posted 28 Oct 2008 Link to this post

    Please explain what is this "$find()" method.  In all of your examples the code assumes we have a $find method.  I've tried it and I do not. 

    -M
  9. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 29 Oct 2008 Link to this post

    Hello Mark,

    Please have a look at these articles:
    $find Shortcut Method

    The Ever-Useful $get and $find ASP.NET AJAX Shortcut Functions


    Greetings,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017