2008 Q3 Doesn't work with focus()

2 posts, 0 answers
  1. Marco Piumi
    Marco Piumi avatar
    32 posts
    Member since:
    Apr 2005

    Posted 25 Nov 2008 Link to this post

    Until release 2008 Q2 , the function <control>.Focus() works well.
    With release 2008 Q3, the function <control>.Focus doesn't work, when in page exists RadFormDecorator !!!

    I tried removing RadFormDecorator, the Focus works fine.
    Add RadFormDecorator, the Focus doesn't work !!!

    Thank you.
  2. Tervel
    Tervel avatar
    1337 posts

    Posted 28 Nov 2008 Link to this post

    Hello Marco,

    I am not aware of any change that we have introduced to change the behavior of RadFormDecorator with that respect. However, setting a control focus using its .Focus method is different for ASP.NET controls and for Telerik controls. You have not specified which type of control you are trying to set focus to, so I am not able to provide more detailed suggestions here.

    Telerik controls set focus in their intialization method - which is the correct way, since in that moment the page initialization is complete. On the other hand, ASP.NET controls's focus is set by outputing some javascript by the MS AJAX framework. Unfortunately the javascript is executed right where it is inserted - and that is - prior to initialization of the ASP.NET AJAX framework.

    As a result, focus is set, then MS AJAX controls are intialized - that is, when RadFormDecorator is initialized as well. The decoration process, performed by the decorator, involves changes to the DOM and moving of elements. This causes the focus set to be lost.

    The only possible workaround is to execute setting of focus with a slight delay to provide the chance for the form decorator to perform its job. Here is how to do it:

    Telerik.Web.UI.RadScriptManager.RegisterStartupScript(Page, GetType(Page), "Focus", String.Format("window.setTimeout('$get('{0}').focus()', 300);", ControlToFocus.ClientID), true);

    All the best,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top