Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi All,

I have 2 Ajax Toolkit's Comboboxes on my asp.net 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:
VB
txtDescription.Attributes.Add("onblur", "javascript:Set_Value();")


JavaScript:
XML
<script type="text/javascript">
      function Set_Value() {
          debugger;
          var intNum = 1;
      }
  </script>


Thanks for advance.
Posted

Yes, the event is called obclur:
http://www.w3schools.com/jsref/event_onblur.asp[^].

This is how it's done using jQuery: http://api.jquery.com/blur/[^].

[EDIT]

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

—SA
 
Share this answer
 
v2
Comments
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?
Sergey Alexandrovich Kryukov 2-Aug-13 16:17pm    
What's the difference if it's a combo box or not. It works for any focusable control.
—SA
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?
Sergey Alexandrovich Kryukov 2-Aug-13 16:27pm    
No, I didn't. I just know it will work for me, that's enough.
—SA
Meg Takahashi 2-Aug-13 16:33pm    
Hi SA,
Thanks for your help.
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.

VB
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.
 
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