Home

ASP.Net MaintainScrollPositionOnPostBack Web User Control

Blog Date 14 June 2021

The Code

    protected void Page_Load(object sender, EventArgs e)
    {
        Parent.Page.MaintainScrollPositionOnPostBack = true;
    ....................

The explanation

You have a regular .aspx page and within that you have a web user control, an .ascx page. Being smart you have placed in the parent page, the .aspx page, the MaintainScrollPositionOnPostBack="True" But when you use the page and there's something like an AutoPostBack="true" in the user control, the child, you find yourself at the top of the page. Urgh.

In the web user control, the child page, NOT in the directives at the top of the page but in the Page_Load add
Parent.Page.MaintainScrollPositionOnPostBack = true;
and we seem to be working fine. I'm figuring if the parent page itself has the keep scrolly thing then it won't apply to the child, but if the child suggests/instructs the parent page it trickles it's way down to the child as well.


Want to play with some of Ren's stuff? dbsolus.co.uk

Reader's Comments

Post Your Comment Posts/Links Rules

Name

Comment

Add a RELEVANT link (not required)

Upload an image (not required)

No uploaded image
Real person number
Please enter the above number below




Home
Admin Ren's Biking Blog