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

Obtain a reference to combo box

7 Answers 110 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
sara
Top achievements
Rank 1
sara asked on 22 Apr 2008, 04:11 PM
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?

7 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 23 Apr 2008, 06:32 AM
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
0
AdamL
Top achievements
Rank 1
answered on 12 May 2008, 02:35 AM
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
0
Veselin Vasilev
Telerik team
answered on 12 May 2008, 08:50 AM
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
0
AdamL
Top achievements
Rank 1
answered on 12 May 2008, 12:47 PM
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
0
Veselin Vasilev
Telerik team
answered on 13 May 2008, 11:20 AM
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
0
Mark
Top achievements
Rank 1
answered on 28 Oct 2008, 09:42 PM
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
0
Veselin Vasilev
Telerik team
answered on 29 Oct 2008, 02:12 PM
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.
Tags
ComboBox
Asked by
sara
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
AdamL
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Share this question
or