How to go back to the same position in a given view inside a multiview

0 comments

Multiviews are commonly used in asp.net pages, but one flaw is observed by users which is the following:Suppose you have web page using Multiview and which is too long that you have to use the vertical scroll bar to focus on a control in the bottom, and that you click on a link to select some data for example , which are dispalyed in a different view of the multiview.


If you go to this view, then you go back to the original view, you will be positioned in the top of the page and you need to click on vertical scroll bar to go back to the original position, this is not convenient for users especially when they are using this page frequently.

Here is the article
which allows to maintain scroll bar position in postbacks, but does not manage mutliple multiviews: My Web application is using many multiviews in the same webform, use the code of that article and did changes to allow to manage many multiviews in web forms using master page as follows:

1) Create the following Javascript functions:
function sstchur_SmartScroller_GetCoords() {
    var scrollX, scrollY, idx, idy;

    if (document.all) {
        if (!document.documentElement.scrollLeft)
            scrollX = document.body.scrollLeft;
        else
            scrollX = document.documentElement.scrollLeft;

        if (!document.documentElement.scrollTop)
            scrollY = document.body.scrollTop;
        else
            scrollY = document.documentElement.scrollTop;
    }
    else {
        scrollX = window.pageXOffset;
        scrollY = window.pageYOffset;
    }


    if (document.getElementById("ctl00_mvid") != null) {
        idx = "ctl00_hx_" + document.getElementById("ctl00_mvid").value;
        idy = "ctl00_hy_" + document.getElementById("ctl00_mvid").value;

        if (document.getElementById(idx) != null) {
            document.getElementById(idx).value = scrollX;
        }
        if (document.getElementById(idy) != null) {
            document.getElementById(idy).value = scrollY;
        }
    }
}

function sstchur_SmartScroller_Scroll() {
    var idx, idy;
    if (document.getElementById("ctl00_mvid") != null) {
        idx = "ctl00_hx_" + document.getElementById("ctl00_mvid").value;
        idy = "ctl00_hy_" + document.getElementById("ctl00_mvid").value;

        if (document.getElementById(idx) != null) {var x = document.getElementById(idx).value;}
        if (document.getElementById(idy) != null) { var y = document.getElementById(idy).value; }
        if (x != null | y != null) { window.scrollTo(x, y); }
    }
}


READ MORE >>

0 comments: