开发者

asp.net user control scroolIntoView is scrolling entire page

开发者 https://www.devze.com 2023-01-25 07:49 出处:网络
I there I\'m using an asp.net user control with a tree view. When I load the page I want to scrool the user control to the selected node in the tree view.

I there

I'm using an asp.net user control with a tree view. When I load the page I want to scrool the user control to the selected node in the tree view. I'm using js function .ScrollIntoView(true). But this is scrolling the entire page (not only what is inside the user control)

here's my code

//js
function ScroolToFirstSelecte开发者_如何学CdCheckBox(ctrlId) {

    Event.observe(window, 'load', function() {
        var tree = document.getElementById(ctrlId + '_MyTreeView');

        var checkBoxes = tree.getElementsByTagName("input");
        var checkBoxesCount = checkBoxes.length;
        for (var i = 0; i < checkBoxesCount; i++) {
            if (checkBoxes[i].checked) {
                checkBoxes[i].scrollIntoView(true);
                break;
            }
        }
    }
    );
}

//aspx.cs
 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), 
                                             "ScrollToSelectedCheckBox", 
                           string.Format("ScroolToFirstSelectedCheckBox('{0}')", 
                           this.UniqueID), 
                           true);

How can I keep the parent page scroll position but continue to set user controll position where I want?

Tks


ok, simply changed

checkBoxes[i].scrollIntoView(true);

with

checkBoxes[i].scrollIntoView(false);

That's it!!!

=P

0

精彩评论

暂无评论...
验证码 换一张
取 消