ASP.NET: How to detect lost focus in user control

Posted on 2009-12-27
Last Modified: 2012-05-08
Is there a way to detect lost focus of a user control? I have 5 user controls in an AJAX Tab Container. One for each tab panel. I want to save the data of each panel as soon as it looses focus. My workaround so far is to catch the ActiveTabChange event and the Click events of the buttons that are on each panel for extra navigation forward and backwars in the tabs. I would like to catch the loosing of the focus on each user control, e.g. if another programm is selected, or a click on any other element on the parent page is done. So in general who can i detect when a user control loses focus?

Question by:MarcusKoch
    LVL 11

    Accepted Solution

    As far as I know, apart from using the client-side event "onblur" there is no other way to detect a focus lost while the page is on the client side. You can add the onblur using the
    ControlID.Attributes.Add("onblur", "someJavaScriptFunctionWhichMayDoSomethingUsingAjax();").
    However, you should have caution that a certain logic will never allow your user to leave the control if there is some kind of validation applied on the data input, so code carefully to cope such situations too.

    Author Comment

    I will try this tomorrow and get back with the results.


    Author Closing Comment

    I finally changed the user interface.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now