Click here to Skip to main content
12,698,476 members (23,927 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET Ajax combobox
Hi All,

I have 2 Ajax Toolkit's Comboboxes on my web page, and I would like to set a value in the 2nd combobox at leaving (losing focus) from the 1st combobox depending on the selection of the 1st combobox. I can capture a lost focus event for a normal text box by adding an attribute 'onblur' to call a javascript function. However, this method does not work for the combobox. Is there any way to achieve this? It does not matter if I do this on client side or server side.

The code for the normal text box:

Code behind:
txtDescription.Attributes.Add("onblur", "javascript:Set_Value();")

<script type="text/javascript">
      function Set_Value() {
          var intNum = 1;

Thanks for advance.
Posted 2-Aug-13 10:58am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Yes, the event is called obclur:[^].

This is how it's done using jQuery:[^].


You actually use onblur but your handler does not do anything useful. What to do? It will depend on what you try to achieve.

Meg Takahashi 2-Aug-13 16:15pm
Hi Sergey Alexandrovich Kryukov,
Thank you for your quick reply. Yes I know onblur and it works fine for asp controls such like a text box as I mentioned in my question. My problem here is to find out if I can use onblur or something equivalent to capture a lost focus event for an Ajax Control Toolkit combobox. Do you have any idea how?
What's the difference if it's a combo box or not. It works for any focusable control.
Meg Takahashi 2-Aug-13 16:23pm
Hi SA,
I don't know why onblur is not working for Ajax Control Toolkit combobox as I thought it would too. However, I actually tried the code and it did not work. Have you ever tried using onblur for Ajax Toolkit controls before?
No, I didn't. I just know it will work for me, that's enough.
Meg Takahashi 2-Aug-13 16:33pm
Hi SA,
Thanks for your help.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I decided not to use the Ajax combobox for other reasons, but I still figured out how to add 'onBlur' attribute for the combobox. You have to add 'onBlur' attribute to the textbox control in the combobox.controls instead of adding it directly to the combobox itself.

Dim txtStartTime As TextBox
txtStartTime = cbxStartTime.FindControl("cbxStartTime_TextBox")
If txtStartTime IsNot Nothing Then
    txtStartTime.Attributes.Add("onBlur", "javascript:Set_EndDateTime(null, this);")
End If

where cbxStartTime is the Ajax combobox, and txtStartTime is the inner control.

This method will fire, but the behavior does not look like 'on lost focus'. It is more like 'on selected item changed'. I guess the textbox loses its focus as soon as a user select an item from the combobox.

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.170118.1 | Last Updated 8 Aug 2013
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