views:

769

answers:

1

I have a user control that contains a gridview and a ModalPopupExtender (MPE). I'm using the MPE to force user decisions after certain ItemCommands from the gridview using the server-side Show() method. Showing the popup and getting postbacks or client-side scripts to execute from the popup both work beautifully.

The issue at hand is that I have no control over where focus lands when the MPE shows. Focus seems to land within the popup, but not on any particular control. A single tab moves focus to the intended control, but I cannot force focus there directly.

As far as I can tell, the show and showing events never fire on the client-side.

I've tried using Focus() and SetFocus() in preRender events for the page, user control, MPE,popup panel and button. None yield the proper result. In fact, calling focus on the button in these events, or anywhere else for that matter, tends to result in focus landing outside of the popup so that no amount of tabs will get focus back where it belongs.

Anyone have any luck controlling the focus in a similar situation?

+3  A: 

I ran into this too awhile back and after fuddling around with it, I just ended up registering a simple javascript to run after the postback to send focus to the desired control.

ScriptManager.RegisterStartupScript(
    typeof(MyPage), 
    "FocusScript", 
    "document.getElementById('" + TextBoxInMPE.ClientID.ToString() + "').focus()", 
    true);
womp
+1. I also ended up using this kind of approach.
Juri