Robbie Mills
Robbie Mills

Reputation: 2945

Returning to the top of the page after submitting a form with Master Pages and Ajax

I have an ASP.NET 4.0 page that I'm trying to reset to the top after a form is submitted in order to display the validation summary.

I am using Ajax and I have a master page with the following simplified code:

 <form id="Form1" runat="server" target="_top" >
    <asp:ScriptManager runat="server" ID="SM1" />
    <asp:UpdatePanel runat="server" ID="UP1"  >
        <ContentTemplate>
                    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                    </asp:ContentPlaceHolder>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>

My content page looks like this:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:ValidationSummary ID="vs1" runat="server" ValidationGroup="ValidateForm" DisplayMode="BulletList"
        CssClass="ValidationSummary" ShowSummary="true" ShowMessageBox="false" />
 < ... Form Field ... >
 < ... Form Field ... >
 < ... Form Field ... >
 < ... Form Field ... >
...
 < ... Form Field ... >


        <asp:ImageButton ID="btnSaveChanges" runat="server" ImageUrl="/Assets/Images/btn-AdminSaveChanges.png"
            ValidationGroup="ValidateForm" CausesValidation="false" OnClick="btnSaveChanges_Click" />

</asp:Content>

What is currently happening is that when a user gets to the bottom of the form and hits the submit button, the page stays where it is and the validation summary is not visible. I'd like to page to reset to the top when there is an error with validation. I've tried changing the maintainscrollposition setting to false in the content pages header, but it doesn't seem to do anything.

Any assistance would be greatly appreciated!

Upvotes: 2

Views: 252

Answers (1)

Tomislav Markovski
Tomislav Markovski

Reputation: 12346

You can execute this javascript

scroll(0,0);

You can add it in the OnClientClick property of your button.

Upvotes: 5

Related Questions