Results 1 to 2 of 2

Thread: Saving to Session onUnload

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240

    Saving to Session onUnload

    I admit it, total newbie to .NET!

    I need to save the .scrollTop of a <DIV> in a Session variable when the page is unloaded. I'm not sure if this can be done in Page_Unload? (I'm using C#).

    Appreciate any input. Thanks.

    cudabean

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    OK, I think I got it. The idea here is I want to save the scroll position of a DIV. I use a Session variable to store the scroll state because I expect the user to go to other pages and refresh the screen, when they come back I want to set the scroll back to where they left it.

    In .aspx I place the following JavaScript functions:
    PHP Code:
    <script language="javascript">
       function 
    saveScrollState() {
          
    scrollPx ListManDataTable.scrollTop;
       }

       function 
    restoreScrollState() {
          
    ListManDataTable.scrollTop scrollPx;
       }
    </
    script
    Then I invoke them on the body tag's onLoad and onUnload
    PHP Code:
    <body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0" onUnload="javascript:saveScrollState();" onLoad="javascript:restoreScrollState();"
    I also use a hidden variable, scrollPx, referenced in the javascript functions:
    PHP Code:
    <form id="dataForm" method="post">
       <
    input type="hidden" name="scrollPx" id="scrollPx" runat="server"
    Also, let us not forget the <DIV> containing the repeater where we want our scroll state preserved:
    PHP Code:
    <div id="ListManDataTable" style="Z-INDEX:1; VISIBILITY:visible; OVERFLOW:auto; WIDTH:690px; POSITION:absolute; HEIGHT:360px">
       <
    asp:Repeater ...>
       </
    asp:Repeater>
    </
    div
    Now for the codebehind:
    Code:
    	override protected void Page_Load( object sender, System.EventArgs e )
    	{
    		string strJScript = "<SCRIPT LANGUAGE=javascript>\n";
    		strJScript += "hidScrollPx = " + Session["patListContentScrollPos"] + ";";
    		strJScript += "</SCRIPT>";
    		Page.RegisterClientScriptBlock("XYZ", strJScript);
    	}
            override protected void Page_Unload()
    	{
    	  Session["patListContentScrollPos"] = hidScrollPx;
    	}
    Also added the property:
    Code:
       protected int hidScrollPx;
    I think that will do it. (Might need to clean up the JavaScript references a little though).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width