Handling the problem of handling scroll bar postbacks in the master page plus AJAX environment

Source: Internet
Author: User
Tags reset

When dealing with the scrollbar problem in the TreeView list, it was found that many popular processing methods did not work, and found that it was not possible to use this popular practice in the master AJAX environment. So self-reliance, with the following code implemented in the master page, using the AJAX environment of the scroll bar after postback is still in place after the problem:

Add this JS on the page:

<script type= "Text/javascript" >

var dispostion = 0;

function Savescroll () {

Dispostion = Tasklistdivid.scrolltop;

}

function Restorescroll () {

Sys.WebForms.PageRequestManager.getInstance (). Add_endrequest (Endrequesthandler);

}

function Endrequesthandler (sender, args) {

Tasklistdivid.scrolltop = dispostion;

}

</script>

Use this div to cover the content (such as the TreeView) that needs this scroll bar.

<div id= "Tasklistdivid" >

Scroll bar content such as TreeView

</div>

In the background CS code is handled as:

This code in order to handle the problem of scroll bar reset start

Scriptmanager.registeronsubmitstatement (this. Page, this. Page.gettype (), "Savepanelscroll", "Savescroll ();");

if (this. IsPostBack)

{

Scriptmanager.registerstartupscript (this. Page, this. Page.gettype (), "Setpanelscroll", "Restorescroll ();", true);

}

End

Note: var dispostion = 0; In the role of Ajax UpdatePanel, it is not reset because of the postback page.

In addition: I implemented this in the ascx, because the use of Ajax pages need ScriptManager, and in the master page has been used, can not be repeated to add the same, so the use of its proxy version.

<asp:scriptmanagerproxy id= "ScriptManagerProxy1" runat= "Server" >

</asp:ScriptManagerProxy>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.