Click here to Skip to main content
12,829,103 members (40,783 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET
Dear All, I am trying to Access Ajax ComboBox DropDown Button from Javascript, But I am able to access the textBox not the DropDown Button.

I would appreciate to know, is there any way to access the dropdown button of Ajax ComboBox control from javascript?
bellow is the page source.
<div id="ctl00_ContentPlaceHolder1_cmbSDURN" class="WindowsStyle">
    <table id="ctl00_ContentPlaceHolder1_cmbSDURN_Table" class="ajax__combobox_inputcontainer" cellspacing="0" cellpadding="0" border="0" style="border-width:0px;border-style:None;border-collapse:collapse;">
            <td class="ajax__combobox_textboxcontainer"><input name="ctl00$ContentPlaceHolder1$cmbSDURN$TextBox" type="text" value="241089" id="ctl00_ContentPlaceHolder1_cmbSDURN_TextBox" onblur="return validateItemExists(this);" onkeydown="return gotoNext(event);" onfocus="focusAndSelect(this);" autocomplete="off" /></td><td class="ajax__combobox_buttoncontainer"><button id="ctl00_ContentPlaceHolder1_cmbSDURN_Button" type="button" style="visibility:hidden;"></button></td>
    </table><ul id="ctl00_ContentPlaceHolder1_cmbSDURN_OptionList" class="ajax__combobox_itemlist" style="display:none;visibility:hidden;">
        <li>-Select SDURN-</li><li>221089</li><li>231089</li><li>241089</li><li>251089</li><li>261089</li><li>281089</li><li>341089</li><li>531189</li><li>561189</li><li>621189</li><li>641189</li><li>651189</li>
    </ul><input type="hidden" name="ctl00$ContentPlaceHolder1$cmbSDURN$HiddenField" id="ctl00_ContentPlaceHolder1_cmbSDURN_HiddenField" value="3" />

I am using bellow javascript function to find out all elements within Ajax ComboBox but it only provides me two elements, TextBox and Hidden Field.

I am looking how can i add javascript event to the button control of ajax comboBox.
Posted 1-Feb-11 18:27pm
Updated 6-Feb-11 22:56pm
Sunasara Imdadhusen 2-Feb-11 0:14am
How do you access it from javascript? please provide snippet of code!
Sandeep Mewara 2-Feb-11 6:16am
Surely we can try if you share across what you did for textbox that worked and dropdown that did not.
Abdul Rahman Hamidy 3-Feb-11 0:20am
I am really sorry for late answer, I was looking for answer Count but that did not increase and I found out comment in my email, any how, I am using bellow to access TextBox
TextBox textBox = cmbSDURN.FindControl("TextBox") as TextBox;
if (textBox != null)
textBox.Attributes.Add("onblur", "return validateItemExists(this);");
textBox.Attributes.Add("onkeydown", "return gotoNext(event);");
textBox.Attributes.Add("onfocus", "focusAndSelect(this);");
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Dropdown is a HTML Select equivalent. Just check the events exposed for a select and then use them as Attributes to add on server side.

Based on snippet above, all the three methods[^] should be there in dropdown too.

If in case you are talking of some button 'in' dropdown then you need to associate the JS after you find that control using Javascript. Use 'child' attribute if needed. You can use IE developer tool to see the complete HTML structure easily and then form the xpath to traverse and get the element needed.
Abdul Rahman Hamidy 6-Feb-11 1:40am
thanks for Reply, well I want to access the button which drops down the list, the button in right side of ajax comboBox. I really dont know what to name that button, like above code I am able the access the textBox but not able to access that button. any ideas please?
Espen Harlinn 6-Feb-11 11:27am
Good answer, my 5
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

In addition to Sandeeps answer you may want to take a look at[^], or any of the jQuery alternatives[^].

Espen Harlinn
Sandeep Mewara 6-Feb-11 12:09pm
jQuery definitely can be one of the ways to resolve it. 5.
Abdul Rahman Hamidy 7-Feb-11 3:52am
thanks for reply but I really dont understand, I dont know whether you guys got my problem or not.
I am still asking the same problem, How can i access Ajax ComboBox DropDown Button Only not the list within the ComboBox, I dont wannt to access li or ul or any item in the list. If you place any Ajax ComboBox inside aspx page, definitly you will get a TextBox, a DropDown Button in your aspx page. I also added the page source in my Question, if you see the button visibility is set to false but stil i can see that button in my aspx page.
Espen Harlinn 7-Feb-11 11:23am
There are a lot of jQuery based combobox alternatives - you need to find one that's implemented using a textbox and it's own button implmentation inside a table, div or whatever.
Abdul Rahman Hamidy 8-Feb-11 3:23am
Thanks, you mean I should go for some alternative but I already used this in my project and if I go for other alternative they may not provide me same functionality as Ajax ComboBox provides, any how. one more issue which i wana share, I have two ComboBox in my aspx page, I want to focus (selectAll) my first ComboBox and while postback i wana focus my 2nd ComboBox. I can focus both but the question remains as when I do focus comboBox the selected Text should get hilighted (selected). any ideas how to achive this, plz?
Espen Harlinn 8-Feb-11 15:08pm
Personally I'm using components from DevExpress -
They provide a rich client side API, usually allowing me to customize nearly all aspects of their behaviour. You'll probably find elements with combobox behaviour based on jQuery that's a lot more flexible than what's available using the ajax toolkit. As long as you want programmatic access to the button of the combobox - you will have to look at the alternatives
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Try this:

WebControl btn = ComboBox1.FindControl("Button") as WebControl;

if (btn != null)
    btn.Attributes.Add("onClick", "jscript:alert('click');");


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170326.1 | Last Updated 2 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100