I have a website that uses the asp GridView.
When a user clicks the paging buttons at the bottom of the gridview, the page reloads to the bottom. I need the page to load to the top instead.
Is there a way to accomplish this inside of PageIndexChanging?
Also, I tried adding MaintainScrollPositionOnPostback="false" in the associated page layout's page tag, but that didn't work.
I managed to resolve the problem on my own.
Here's my solution:
I used ClientScriptManager and RegisterClientScriptBlock to run a piece of javascript to set window location to a new anchor ("news"). And then, I added the "news" anchor to my page layout (near the top of the page).
ClientScriptManager script = Page.ClientScript;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script language='javascript'>");
sb.Append(@"window.location.hash='news';");
sb.Append(@"</script>");
script.RegisterClientScriptBlock(typeof(string), "scroll", sb.ToString(), false);
Hope this helps someone in the future!