Setting Control Focus in an Ajax Update Panel

RadicalWacko March 23rd, 2008

I’ve decided to start posting the solutions I find in irritating little problems that take me forever to find.  Some of these will probably be obvious, but hopefully it might save someone’s time.  My current problem was that I had a DotNetNuke module that was sitting in a AJAX Update Panel.  I needed to set the focus to a particular control based upon a post back click on a radio button.  The standard focus() method didn’t work and neither did the old fashioned RegisterClientScriptBlock stuff with a provided JavaScript function.  Turns out there is an extremely easy way to do this which is to use the ScriptManager SetFocus method using the base Page for the control as shown below:

ScriptManager.GetCurrent(Me.Page).SetFocus(txtApplicationDate)

Hope that helps someone.

  • Tags:

4 Responses to “Setting Control Focus in an Ajax Update Panel”

  1. houshangon 15 Jan 2009 at 12:14 am

    hello
    i am appreciating from your help
    but i have another problem
    when the focus send to textbox the mouse curser comes to start of
    the text.
    thank you

  2. RadicalWackoon 18 Jan 2009 at 7:25 pm

    Well I don’t know off the top of my head, but I would guess you could use the same process to set the index of the textbox or something like that.

  3. Magnificaton 05 Feb 2009 at 8:53 am

    It Works. Clean Solution & very useful

    Thanks a Lot!!!!!

  4. keeganon 30 Mar 2009 at 10:48 pm

    Thank you. So simple.

Trackback URI | Comments RSS

Leave a Reply