OnFocus causing Parent to Scroll to Top

2 posts, 0 answers
  1. Dan
    Dan avatar
    139 posts
    Member since:
    Feb 2011

    Posted 29 Jul 2013 Link to this post

    We have several pages that are rendered in RadWindows from a Parent page.  To speed along keyboard driven entry, we were setting the focus to the first prompt in the RadWindow - but when we do this, it seems that the Parent Screen will always scroll to the top (which is not the behavior we want).  We have moved the focus code from code behind to javascript, but the problem persists.

    Is there a recommended way to handle this?  For now we have removed the .focus() calls and the problem has gone away - but we would like to set the focus on load in the RadWindow while holding the scroll position on the parent page.
  2. Danail Vasilev
    Danail Vasilev avatar
    1502 posts

    Posted 01 Aug 2013 Link to this post

    Hello Dan,

    The call to Focus() is a common reason for such behavior. RadWIndow renders with JavaScript as the first child of the <form> element, and then positions absolutely. The server-side Focus() method registers a script to execute and call the client-side focus() method of the designated control, yet this script runs too early and the browsers tend to miscalculate the actual position of the textbox and believe it is in the beginning of the form.

    What should be done is to use the Sys.Application.Load event to add the focus and use a small timeout. An example of this can be seen in this forum post.

    Danail Vasilev
    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 the blog feed now.
Back to Top