User checks checkbox and scrolls down, vertical position moves back to before scrolling of user

1.2k Views Asked by At

The issue im having is a user checks the checkbox and scrolls down, the vertical position moves back to before scrolling of user about a second later.

I have a checkbox inside a repeater, the checkbox has autopost set to true and i run some code if its checked/unchecked. I also have maintainscrollbackposition as true.

Can anyone help please? can this be fixed?

<asp:Repeater ID="rpFactorLeadershipStrengths" OnItemDataBound="rpFactorLeadershipStrengths_OnItemDataBound" runat="server">
    <ItemTemplate>
        <label class="checkbox">
            <asp:CheckBox ID="cbLeadershipStrengthStatement" AutoPostBack="true" OnCheckedChanged="cbLeadershipStrengthStatement_OnCheckedChanged" runat="server" />
            <small><asp:Literal ID="ltLeadershipStrengthStatement" runat="server" /></small>
        </label>
        <asp:HiddenField ID="hfLeadershipStrengthStatementId" runat="server" />              
    </ItemTemplate> 
</asp:Repeater> 
2

There are 2 best solutions below

0
On

For Same you have to Do these steps

1 Write following code in Page_Load event of page.

protected void Page_Load(object sender, EventArgs e)
{
    MaintainScrollPositionOnPostBack = true;
}

2 Right click on solution explorer > Add New Item

Select Browser File and add it to App_Browsers folder.

Add MaintainScrollPositionOnPostback capability to this browser file as written below.

 <browsers>
 <browser refID="Mozilla">
 <capabilities>
   <capability name="supportsMaintainScrollPositionOnPostback"
               value="true" />
 </capabilities>

3 You can use scrollsaver javascript file to maintain scroll position In Chrome.

<script type="text/javascript" src="scrollsaver.min.js"></script>

For Other Reference please visit this link See Reference

Hope it will helps you.

0
On

I had a similar problem caused by the async postback. I worked around the default scroll behaviour by adding the following javascript to the page to overwrite the scroll action.

<script type="text/javascript">
    window.scrollTo = function () { }
</script>