Site icon Ryadel

ASP.NET - MantainScrollPositionOnPostback for Chrome and most recent browsers

System.Web.HttpException (0x80004005): The application is configured to issue secure cookies - Cause e soluzioni del problema

To keep (or to say it better, to recover) the page scrollbar position after a postback is definitely a feature any form-containing page should have. This used to be a trival task for any ASP.NET developer, who could just by add a simple configuration parameter to their code:

On web.config level:   <pages maintainScrollPositionOnPostBack="true" />

On page level:   <%@ Page MaintainScrollPositionOnPostback="true" %>

On code-behind level:  Page.MaintainScrollPositionOnPostBack = true;

Unfortunately all these methods, other than being unavailable with Razor, aren't working anymore with any recent non-IE browser. Sure, it's still possible to detect and configure the behavior of each one of them by using the ASP.NET Browser Definition Files accordingly, but in order to achieve better results it's advised to adopt a centralized, versatile solution. Here's a simple script based on the popular jQuery framework who does the trick in a cross-browser compatible way:

For WinForms:

For Razor (and also for any web page, since it's pure HTML+JS):

Needless to say, in order to make these scripts work you have to place the input element on top (asp:HiddenField for the WinForms one) inside the form element who will handle the Postback.

 

 

Exit mobile version