How to put focus on a control that is inside an update panel after closing boostrap modal

35 views Asked by At

I have a Bootstrap Modal, that I use as an error popup, with a label - to show an error message - and a button on it.

When the user clicks the button it closes the modal and should set focus to a specific control, that is inside an update panel, on the page. But when the modal closes the control doesn't get focus.

Is there a way I can do this, preferably without using javascript?

This is the code I'm using. I've tried with the .Focus above and below ScriptManager, but like I say the control doesn't get focus...

Page.MaintainScrollPositionOnPostBack = False
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType(), "HideErrors", "$('#modErrors').modal('hide')", True)
Me.txtCVRegDate.Focus()

*The ScriptManager closes my modal (called modErrors)

1

There are 1 answers

0
sconners On

I've actually come up with a workaround.

I set the focus to the control before opening the modal. So when the modal is closed the page is already at the correct scroll position.

Whether, or not, that is the right way to go about it...I don't know. But it works.