Set focus to a TextBox (in a ModalPopupExtender)

I have a web page where couple of ModalPopupExtender and Panel exist, and I want to set focus to TextBox inside the corresponding pop up window when user click the target button accordingly. I think it's a common requirement to set the focus to a specific TextBox immediately when user open up the window. However, I always get the error message "Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus".

Understand that the modal pop up window and the TextBox inside are hidden by default, while setting focus on that TextBox upon the click of TargetControl seems impossible. Fortunately, google showed me an article by Jaspreet and he showed how he solve this problem by using the setTimeOut and two JavaScript functions (set the focus by 1 second delay).

Published Wednesday, July 28, 2010 12:55 AM by Colt
Filed under:

Comments

# re: Set focus to a TextBox (in a ModalPopupExtender)

I want to know answer this

Wednesday, September 22, 2010 4:11 AM by BeEr

# re: Set focus to a TextBox (in a ModalPopupExtender)

where can i find out the source code and javascript for doing this...

Monday, March 14, 2011 8:15 AM by Simerpreet Kaur

# re: Set focus to a TextBox (in a ModalPopupExtender)

Sys.Application.add_load(function() {

       var popup = $find('<%= ajaxModalPopupControl.ClientID %>');

       popup.add_shown(function() { $get('<%= txtSearch.ClientID %>').focus(); });

   });

P.S/ add_shown event *

Monday, April 18, 2011 9:32 AM by Thurein

# re: Set focus to a TextBox (in a ModalPopupExtender)

Hi,

This code is working fine with IE7 and IE8.

But not working in firefox.

Monday, June 13, 2011 6:20 AM by Aanjaneyulu

# re: Set focus to a TextBox (in a ModalPopupExtender)

Hi,

Thanks.It is working in firefox also.

Monday, June 13, 2011 6:25 AM by Aanjaneyulu

# re: Set focus to a TextBox (in a ModalPopupExtender)

wher we have to place that code?

Monday, November 21, 2011 7:18 AM by Raj

Leave a Comment

(required) 
(required) 
(optional)
(required)