I have a slightly different scenario and requirements, but the same essential problem -- needing a way to set focus on either the modal Panel so that DefaultButton works, or on the CancelControl (LinkButton) in the modal.
My ModalPopup is for displaying an error message to the user when they fail a login. It has a dummy HiddenField specified for the TargetControlID and is programmatically displayed by calling Show() in the codebehind. The contents of the modal include only
the error text and a [Close] LinkButton to dismiss the modal. The primary target usergroup is standardized on IE, which doesn't allow javascript .focus() on hidden elements.
With no "real" TargetControl, shown/showing events never fire after wiring handlers with add_shown/add_showing. Emitting client script to immediately focus the [Close] LinkButton also did not work -- it seems IE still considered the control to be hidden
at that point.
So I used setTimeout for a short delay to allow visibility of the button to "catch up" after the modal.Show().
Here's the C# code:
mpeLoginError.Show();
// Hack to set focus to Close button so user can dismiss modal with Enter keypress. ScriptManager.RegisterStartupScript( this, this.GetType(), "FocusScript", "setTimeout(function(){$get('" + btnErrorClose.ClientID + "').focus();}, 100);", true);
rajan_top1
Member
160 Points
104 Posts
Re: Set Focus on Textbox in modalPopup Panel
Jul 05, 2010 05:43 AM|LINK
Yes Really it is so easy to apply the focus inside the modalpopup panel.
rajan_top1
Member
160 Points
104 Posts
Re: Set Focus on Textbox in modalPopup Panel
Jul 05, 2010 05:53 AM|LINK
Have u got both I.E. and Mozila ?
I Use that code i got Correct in I.E but that code does not support in Mozila bowser
wonkim00
Member
4 Points
2 Posts
Re: Set Focus on Textbox in modalPopup Panel
Sep 14, 2010 08:45 PM|LINK
I have a slightly different scenario and requirements, but the same essential problem -- needing a way to set focus on either the modal Panel so that DefaultButton works, or on the CancelControl (LinkButton) in the modal.
My ModalPopup is for displaying an error message to the user when they fail a login. It has a dummy HiddenField specified for the TargetControlID and is programmatically displayed by calling Show() in the codebehind. The contents of the modal include only the error text and a [Close] LinkButton to dismiss the modal. The primary target usergroup is standardized on IE, which doesn't allow javascript .focus() on hidden elements.
With no "real" TargetControl, shown/showing events never fire after wiring handlers with add_shown/add_showing. Emitting client script to immediately focus the [Close] LinkButton also did not work -- it seems IE still considered the control to be hidden at that point.
So I used setTimeout for a short delay to allow visibility of the button to "catch up" after the modal.Show().
Here's the C# code:
Hope that helps someone.