How to avoid page refresh when using SetFocusOnError = "true"

I have a required field validator where I added a property for SetFocusOnError = "true"

                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorFirstName" runat="server" CssClass="message-validation-color"
                        Text="Required first name!"  
                        SetFocusOnError="true"
                        ControlToValidate="txtFirstName" />
                        <br/>

But whenever I click the submit button. Focus will be set in the text box for the name (which is actually my goal). BUT then reloading the page and focus will be lost. I noticed that when I do not turn on SetFocusOnError = "true", the page does not reload.

Do I need to add any checks when using SetFocusOnError = "true"?

I just want the focus to be in the field where there is an error, and NOT to reload the page.

+3
source share
1 answer

2 things to try:

  • , "ValidationGroup", ,
0

All Articles