2

I am currently working on an ASP.Net project that has a large number of js files, most from third party sources. On a number of pages, the focus is being set to a control other than the one I'm setting it to in code-behind (Control.Focus()). How can I figure out how, why, and where the focus is being changed?

I have installed FireFocus for FireBug so I can see the focus being changed, but I cannot see the cause.

Keith
  • 2,563
  • 1
  • 17
  • 9
  • Duplicate question here: http://stackoverflow.com/questions/570960/how-to-debug-javascript-jquery-event-bindings-with-firebug-or-similar-tool – Moby's Stunt Double Apr 04 '13 at 19:10
  • 2
    Try using jQuery to add a `focus` event handler to the element that is wrongly receiving focus. From there set a breakpoint and look at the call stack to figure out where the focus is being set from. I am not sure if FireBug shows the call stack (it should) but Chrome developer tools does. – Danny Apr 04 '13 at 19:30

1 Answers1

1

Using the link provided by Moby's Stunt Double, I added the following code to the bottom of my page and every time the focus was changed, the call stack was dumped to my console so I could trace the source.

<script type="text/javascript">
    $("#TabInformation").on("focus", function (event) {
        try { throw new Error("dummy"); } catch (e) { console.log(e.stack); }
    });
</script>
Keith
  • 2,563
  • 1
  • 17
  • 9