Thursday, May 28, 2009

ASP.Net Ajax - Control.focus() not working after implementing Update Panel

If the control.focus() method is not working in your Web Application after implementing or switching to the Ajax version.

If you implemented Ajax version by installing the ajax extentions and placing the Script Manager Control on the Top of the web page and added Update Panel after the Script Manager Control. After that you shifted the existing web page contents using CUT and Paste / or any other method into Update Panel.

Not your Current working version of this webpage is using CONTROL.FOCUS() method at (serveral) locations.

Now when you run the Webpage with Ajax Implemented, then CONTROL.FOCUS() method is working.

But, The control focus is working fine when the script manger and update panel tags are commented.

THE SOLUTION TO THIS PROBLEM is :

Use ScriptManager.SetFocus(TargetControl) during partial postbacks and pass that control as a paramenter to this function.

For. Eg.
If you are presently using D1.FOCUS where D1 is a Dropdown control in the current (Without Ajax) webpage.

Now you should use.

ScriptManager.SetFocus(D1)

You are to make the above change everywhere you are facing this problem.

1 comment:

Unknown said...

Thanx a lot. This information was very much useful as i couldnt find it anywhere else as i googled through.
Thank u once again.