Move to anchor tag after page postback


1. Set MaintainScrollPositionOnPostback="false" in the @Page directive.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" Title="Test anchor Page" MaintainScrollPositionOnPostback="false" %>

2. Create a named anchor in the HTML.
<a name="MOVEHERE"></a>

3. Write the follwoing code in the page load.
if (IsPostBack)
{
ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#MOVEHERE';", true);
}

Comments