简体   繁体   中英

Maintain horizontal and vertical ScrollPosition on Postback in ASP.NET

The coding is in ASP.NET C#.
I have a gridview, with say 1000 records and I am inline editing one of the rows.
On Clicking Update, I would like my Grid to be on the exact xy position it was on before the postback happened.
If you are thinking along the lines of using the Page directive, MaintainScrollPositionOnPostback="true" , no, it didnt work for me
What is the most optimal method?

Using the UpdatePanel control to wrap your grid.

Another way would be to use ajax instead like using the jqGrid component.

You could use an AJAX UpdatePanel to avoid reloading the whole page. That will work even when MaintainScrollPositionOnPostback for some reason does not.

create a js method to record the current scroll position of the page to a hidden server control. you could set this up as a handler on each update button, or onscroll, or anything else that will fire after you manually scroll to your edit row and before the postback occurs.

during server processing, generate js code that will restore the scroll position. register this as a startup script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM