none
如何在应用母版下,网页刷新后panel的滚动条保持不变? RRS feed

答案

  • 你可以在滚动事件里将滚动位置放置在cookie里,页面加载的时候先读取cookie的值,然后进行设置Panel的滚动位置
    【孟子E章】
    2009年5月5日 6:39
    版主
  • 楼主,你好

    你也可以采用AJAX,详细可以参考下面的代码。
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
    
    <script runat="server">
    
    </script>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
       

    <asp:Panel ID="Panel1" runat="server" Width="200px" Height="250" ScrollBars="Auto">

    <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" Height="500px" Width="1036px"></asp:TextBox> hhdhd<asp:Button ID="Button1" runat="server" Text="Button" /> </ContentTemplate> </asp:UpdatePanel>

    </asp:Panel>

    </asp:Content>

    Microsoft Online Community Support
    2009年5月6日 3:42
  • 楼主你好!

    我同意老孟的方案,可以借助Cookie或UserData(仅IE可用)等方式来保存滚动条的位置。

    你也可以在window.onunload时保存滚动条位置,并在下次的window.onload时读取并设置该位置,可参考如下代码(使用UserData):

    一个需求相同的帖子:http://forums.asp.net/p/1377826/2912037.aspx#2911629

    谢谢!

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
        <title></title>
    
        <script type="text/javascript" language="javascript">
            function getFileName() {
                var url = this.location.href
                var pos = url.lastIndexOf("/");
                if (pos == -1)
                    pos = url.lastIndexOf("\\")
                var filename = url.substr(pos + 1)
                return filename;
            }
    
            function fnLoad() {
                with (window.document.body) {
                    addBehavior("#default#userData");    // make the body tag support the userdate 
                    load("scrollState" + getFileName());    // get the state in userdate 
                    scrollLeft = getAttribute("scrollLeft");
                    scrollTop = getAttribute("scrollTop");
                }
            }
    
            function fnUnload() {
                with (window.document.body) {
                //replace window.document.body to the element who need maintain scroll state
                    setAttribute("scrollLeft", scrollLeft);
                    setAttribute("scrollTop", scrollTop);
                    save("scrollState" + getFileName());
                }
            }
            window.onload = fnLoad;
            window.onunload = fnUnload; 
    
        </script>
    
    </head>
    <body>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
    </body>
    </html>
    

    http://blodfox777.cnblogs.com
    2009年5月7日 1:45

全部回复

  • 你可以在滚动事件里将滚动位置放置在cookie里,页面加载的时候先读取cookie的值,然后进行设置Panel的滚动位置
    【孟子E章】
    2009年5月5日 6:39
    版主
  • 楼主,你好

    你也可以采用AJAX,详细可以参考下面的代码。
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
    
    <script runat="server">
    
    </script>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
       

    <asp:Panel ID="Panel1" runat="server" Width="200px" Height="250" ScrollBars="Auto">

    <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" Height="500px" Width="1036px"></asp:TextBox> hhdhd<asp:Button ID="Button1" runat="server" Text="Button" /> </ContentTemplate> </asp:UpdatePanel>

    </asp:Panel>

    </asp:Content>

    Microsoft Online Community Support
    2009年5月6日 3:42
  • 楼主你好!

    我同意老孟的方案,可以借助Cookie或UserData(仅IE可用)等方式来保存滚动条的位置。

    你也可以在window.onunload时保存滚动条位置,并在下次的window.onload时读取并设置该位置,可参考如下代码(使用UserData):

    一个需求相同的帖子:http://forums.asp.net/p/1377826/2912037.aspx#2911629

    谢谢!

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
        <title></title>
    
        <script type="text/javascript" language="javascript">
            function getFileName() {
                var url = this.location.href
                var pos = url.lastIndexOf("/");
                if (pos == -1)
                    pos = url.lastIndexOf("\\")
                var filename = url.substr(pos + 1)
                return filename;
            }
    
            function fnLoad() {
                with (window.document.body) {
                    addBehavior("#default#userData");    // make the body tag support the userdate 
                    load("scrollState" + getFileName());    // get the state in userdate 
                    scrollLeft = getAttribute("scrollLeft");
                    scrollTop = getAttribute("scrollTop");
                }
            }
    
            function fnUnload() {
                with (window.document.body) {
                //replace window.document.body to the element who need maintain scroll state
                    setAttribute("scrollLeft", scrollLeft);
                    setAttribute("scrollTop", scrollTop);
                    save("scrollState" + getFileName());
                }
            }
            window.onload = fnLoad;
            window.onunload = fnUnload; 
    
        </script>
    
    </head>
    <body>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
    </body>
    </html>
    

    http://blodfox777.cnblogs.com
    2009年5月7日 1:45