Click here to Skip to main content
Rate this: bad
good
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 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:
txtDescription.Attributes.Add("onblur", "javascript:Set_Value();")
 
JavaScript:
<script type="text/javascript">
      function Set_Value() {
          debugger;
          var intNum = 1;
      }
  </script>
 
Thanks for advance.
Posted 2-Aug-13 10:58am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Comments
Meg Takahashi at 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 at 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 at 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 at 2-Aug-13 16:27pm
   
No, I didn't. I just know it will work for me, that's enough.
—SA
Meg Takahashi at 2-Aug-13 16:33pm
   
Hi SA,
Thanks for your help.
Sergey Alexandrovich Kryukov at 2-Aug-13 17:12pm
   
Sure.
—SA
Rate this: bad
good
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.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.150129.1 | Last Updated 8 Aug 2013
Copyright © CodeProject, 1999-2015
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