5

我想保持滚动位置RadPanelBar。我RadPanelBar被放置在自动刷新的页面中。当我向下滚动条时,RadPanelBar它会在页面刷新时向上。它不应该。我正在尝试使用以下代码处理它,但它不起作用。我错过了什么吗?

这是我的 JavaScript

<script type="text/javascript">
function SetScrollPositionOnlineContacts() {

    //var pane = splitter.GetPaneById("RadPanelBarRoster");
    //document.getElementById("RadPanelBarRoster").scrollTop;

    var splitter =$find("RadSplitterBottomParent");
    var intY =  splitter.GetPaneById("RadPanelBarRoster").scrollTop;

    var date = new Date();
    date.setTime(date.getTime() + (1 * 60 * 60 * 1000));
    var expires = "; expires=" + date.toGMTString();
    document.cookie = "cookieDivOnlineContacts" 
                      + "=" 
                      + intY 
                      + expires + "; path=/";
    //document.title = intY;
}

function readCookieOnlineContacts(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}
    </script>

这是我的HTML代码:

<telerik:RadSplitter ID="RadSplitterBottomParent" runat="server" Height="100%" 
    Width="100%" Orientation="Vertical" BackColor="#ECECFF" Skin="WebBlue" 
    LiveResize="True" SplitBarsSize="" HeightOffset="124" Visible="true" 
    BorderSize="0" PanesBorderSize="0">

    <!-- Start Left Roster Panel -->
    <telerik:RadPane ID="RadPaneRoster" runat="server" Width="220px" 
        Scrolling="None">
        <telerik:RadContextMenu ID="RadContextMenuRoster" runat="server" 
            OnClientItemClicked="onRosterContextMenuClick" 
            EnableShadows="True">
            <Items>
                <telerik:RadMenuItem runat="server" Text="View 
                    Conversation">
                </telerik:RadMenuItem>
                <telerik:RadMenuItem runat="server" Text="View Properties">
                </telerik:RadMenuItem>
                <telerik:RadMenuItem runat="server" Text="Add to Favourites" 
                    Enabled="False">
                </telerik:RadMenuItem>
            </Items>
        </telerik:RadContextMenu>
        <telerik:RadPanelBar ID="RadPanelBarRoster" runat="server" 
            Skin="Metro" 
            Width="100%" onscroll="SetScrollPositionOnlineContacts()"
            Height="3000px" OnClientItemClicked="onRosterClick" 
            OnClientContextMenu="onRosterContextMenu"
            PersistStateInCookie="True" Style="width: 100%; border-top: 0; 
            border-bottom: 0;
            z-index: 2" ExpandMode="FullExpandedItem" EnableViewState="True" 
            ViewStateMode="Inherit"
            OnItemClick="RadPanelBarRoster_ItemClick">
        </telerik:RadPanelBar>
    </telerik:RadPane>
</telerik:RadSplitter>

这是我在页面后面的代码:

protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {
        StringBuilder sbScript = new StringBuilder();
        sbScript.Append(
            "<script language='JavaScript' type='text/javascript'>");
        //For order Panel
        sbScript.Append(
        "document.cookie = cookieDivOnlineContacts + \"" + 
        "=\" + \"\" + -1 + \"; path=/\";");

        sbScript.Append("</script>");
        //// Make use ScriptManager to register the script
        ScriptManager.RegisterStartupScript(
            this, 
            this.GetType(), 
            "@@@@MyCallBackAlertScript", 
            sbScript.ToString(), 
            false);
    }

    StringBuilder sbScript1 = new StringBuilder();
    sbScript1.Append(
        "<script language='JavaScript' type='text/javascript'>");
    //For order Panel
    sbScript1.Append(
        "var strCookOnlineContacts = " + 
        "readCookieRfqOrder(\"cookieDivOnlineContacts\"); " + 
        "document.getElementById(\"RadPanelBarRoster\").scrollTop " + 
        "= strCookOnlineContacts;");

    sbScript1.Append("</script>");

    // Make use ScriptManager to register the script
    ScriptManager.RegisterStartupScript(
        this, 
        this.GetType(), 
        "@@@@MyCallBackAlertScript", 
        sbScript1.ToString(), 
        false);

}

我是初学者,所以请给我适当的帮助。

4

1 回答 1

2

你正在尝试使用 cookie,这里还有一段代码试试这个,把这段代码放在 JavaScript 部分

这将在请求开始时保存滚动位置,并在页面完全呈现时存储回滚位置。

 function pageLoad()
        {
            $("your radID").scroll(function() {
            SaveScrollPosition();
            });
        }

    var yPos;
        function SaveScrollPosition(){
         yPos = $("your rad bar id").scrollTop(); 
        }

        function ReturnPos() {
        $("your radID").scrollTop(yPos);
        }


  function OnResponseEnd(sender ,eventArgs)
        {
            ReturnPos();
        }

  function OnRequestStart(sender ,eventArgs)
        {

            SaveScrollPosition();
        }

这是你的 html

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" ClientEvents-OnRequestStart="OnRequestStart" ClientEvents-OnResponseEnd="OnResponseEnd">
// you code here
</telerik:RadAjaxManager>

我相信这会解决你的问题。谢谢 如果是解决方案,请将其标记为答案。

于 2012-10-10T07:18:40.293 回答