locked
MaintainScrollPositionOnPostback issues RRS feed

  • Question

  • User350923160 posted

    Hello everyone,

    I am using Response.Redirect(Request.RawUrl); at the end of a button click even which updates data in sql tables to prevent updating again when the user refreshes the page. It is working perfectly but the MaintainScrollPositionOnPostback stopped working and the page goes back up every time I click the update button. Is there any way I can maintain the position of the page when the user clicks the button and keep using Response.Redirect(Request.RawUrl)? 

    Wednesday, November 14, 2018 10:03 PM

Answers

  • User350923160 posted

    Thanks for the suggestion. I ended up doing something similar. The solution was getting the ID of any object in the grid-view and append "_" + current row index and append it to Response.Redirect(Request.RawUrl); like you suggested. 

    So the final format was Response.Redirect(Request.RawUrl + "#[gridviewID]_[AnyObjectID]_" + [row index]);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 15, 2018 1:27 PM

All replies

  • User475983607 posted

    aazizasp

    I am using Response.Redirect(Request.RawUrl); at the end of a button click even which updates data in sql tables to prevent updating again when the user refreshes the page. It is working perfectly but the MaintainScrollPositionOnPostback stopped working and the page goes back up every time I click the update button. Is there any way I can maintain the position of the page when the user clicks the button and keep using Response.Redirect(Request.RawUrl)? 

    No.

    Response.Redirect(Request.RawUrl) causes the browser to do an HTTP GET after the postback is completed which refreshes the page and clears MaintainScrollPositionOnPostback.  You can add (bind) bookmarks in bound control server control.

    <a href="#SomeUniqueId">got to id</a>
    ...
    <td><span id="SomeUniqueId"></span></td>

    Then Response.Redirect(Request.RawUrl + "#SomeUniqueId") will scroll the page to the bookmark.

    https://www.w3schools.com/html/html_links.asp

    Wednesday, November 14, 2018 10:20 PM
  • User350923160 posted

    I do have a gridview with many rows, how would I do that with the bookmarks method?

    Wednesday, November 14, 2018 11:53 PM
  • User475983607 posted

    I do have a gridview with many rows, how would I do that with the bookmarks method?

    First read the link in my previous thread so you understand how bookmarks work.  Perhaps build a simple demo.

     Then simply redirect to an id within the grid.

    Thursday, November 15, 2018 12:18 AM
  • User350923160 posted

    Thanks for the suggestion. I ended up doing something similar. The solution was getting the ID of any object in the grid-view and append "_" + current row index and append it to Response.Redirect(Request.RawUrl); like you suggested. 

    So the final format was Response.Redirect(Request.RawUrl + "#[gridviewID]_[AnyObjectID]_" + [row index]);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 15, 2018 1:27 PM
  • User475983607 posted

    Thanks for the suggestion. I ended up doing something similar. The solution was getting the ID of any object in the grid-view and append "_" + current row index and append it to Response.Redirect(Request.RawUrl); like you suggested. 

    So the final format was Response.Redirect(Request.RawUrl + "#[gridviewID]_[AnyObjectID]_" + [row index]);

    No you did exactly as I suggested IMHO...

    Thursday, November 15, 2018 2:12 PM
  • User350923160 posted

    I did not use 

    <a href="#SomeUniqueId"></a>

    because I didn't need a bookmark but that is why I said something similar regarding Response.Redirect(Request.RawUrl + "#SomeUniqueId"). I think the important thing is that we got it solved and I thank you again for that.

    Thursday, November 15, 2018 3:58 PM
  • User475983607 posted

    I did not use 

    <a href="#SomeUniqueId"></a>

    because I didn't need a bookmark but that is why I said something similar regarding Response.Redirect(Request.RawUrl + "#SomeUniqueId"). I think the important thing is that we got it solved and I thank you again for that.

    That was an example...

    Thursday, November 15, 2018 5:41 PM