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

2008 Q3 Doesn't work with focus()

1 Answer 46 Views
FormDecorator
This is a migrated thread and some comments may be shown as answers.
Marco Piumi
Top achievements
Rank 2
Marco Piumi asked on 25 Nov 2008, 03:25 PM
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.

1 Answer, 1 is accepted

Sort by
0
Tervel
Telerik team
answered on 28 Nov 2008, 10:58 AM
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,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
FormDecorator
Asked by
Marco Piumi
Top achievements
Rank 2
Answers by
Tervel
Telerik team
Share this question
or