This is a migrated thread and some comments may be shown as answers.

How to Handle Focus and Blur Events for RadButton

3 Answers 203 Views
Button
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 27 Feb 2013, 02:30 PM
I want to call a javascript function when a radButton receives focus by tabbing onto the control.  Similarly, call a javascript function when radButton loses focus.  How can this be accomplished?

3 Answers, 1 is accepted

Sort by
0
MasterChiefMasterChef
Top achievements
Rank 2
answered on 27 Feb 2013, 05:34 PM
Hi Mark,

The built-in events for the RadButton are right here in the RadButton documentation. The closest events available for what you are trying to do are the OnClientMouseOver and OnClientMouseOut events.  Unfortunately, these events do not check for focus or blur. In your code behind you could set the focus manually to a specific RadButton (example here), and use the document.activeElement selector to select the focused item. I'm not quite sure if there is an equivalent selector available to select a blurred element.

Hopefully this helps,
Master Chief
0
Danail Vasilev
Telerik team
answered on 01 Mar 2013, 01:06 PM
Hi Guys,

RadButton is rendered as an input element wrapped inside of a span element. Therefore in order to tab in the button you can set its tabindex property. After that you can simply use the jQuery's focus and  blur methods to attach handlers to these events. For example:

    <script type="text/javascript">
        function pageLoad() {
            //Getting the button's wrapper
            button1 = $find("<%=RadButton1.ClientID %>");
            buttonWrapper = $telerik.$(button1.get_element());
 
            //Set tabindex attribute to the span element
            buttonWrapper.attr("tabindex", "0");
 
            //Add event handler to focus event
            buttonWrapper.focus(function () {
                alert('Handler for .focus() called.');
            });
 
            //Add event handler to focus event
//            buttonWrapper.blur(function () {
//                alert('Handler for .blur() called.');
//            });
        }                
    </script>

Note that I set the tabindex attribute of the span to 0 through JavaScript, as the tabIndex property of the RadButton does not get "0" as a value. This is an issue which our developers are aware of and will consider a fix.


All the best,
Danail Vasilev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Mark
Top achievements
Rank 1
answered on 04 Mar 2013, 06:16 PM
Thanks for the replies.  By acquiring the element I'm able to implement the needed behaviors.
Tags
Button
Asked by
Mark
Top achievements
Rank 1
Answers by
MasterChiefMasterChef
Top achievements
Rank 2
Danail Vasilev
Telerik team
Mark
Top achievements
Rank 1
Share this question
or