Click here to Skip to main content
15,867,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
XML
<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;">
        <tr>
            <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>
        </tr>
    </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" />
</div>


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
Updated 6-Feb-11 21:56pm
v2
Comments
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);");
}

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.
 
Share this answer
 
Comments
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
In addition to Sandeeps answer you may want to take a look at
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/ComboBox/ComboBox.aspx[^], or any of the jQuery alternatives[^].

Regards
Espen Harlinn
 
Share this answer
 
Comments
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 - http://www.devexpress.com/Products/NET/Controls/ASP/
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
Try this:

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

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


Regards,
Henry
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900