script not working when executed once
<p>I have the following code on my web page. SetDivPosition and window.onload is to mantain the scroll bar position on postback on div tag and $(document).ready 
function is when the user first visits this page than the scroll bar needs to be all the way to the bottom, this needs to be done only one time when user first
 got redirected to the page. If I first visit the page than the scroll bar is all the way to the top. I want it to be at the bottom and 
also mantain the scroll bar position on the postbacks. I can do only one thing at this time, I can either maintain the scroll bar position or 
move the scroll bar all the way to the bottom. Can I accomplish both the things. </p>

<p>any help will be greatly appreciated.</p>

<pre><code>    &lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
      &lt;script src="Scripts/jquery-1.9.1.js" type="text/javascript"&gt;&lt;/script&gt;

    &lt;script src="Scripts/jquery.cookie.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script type = "text/javascript"&gt;
        function SetDivPosition() {
            var intY = document.getElementById("scrollArea").scrollTop;
            document.cookie = "yPos=!~" + intY + "~!";
        }

        window.onload = function () {
            var strCook = document.cookie;
            if (strCook.indexOf("!~") != 0) {
                var intS = strCook.indexOf("!~");
                var intE = strCook.indexOf("~!");
                var strPos = strCook.substring(intS + 2, intE);
                document.getElementById("scrollArea").scrollTop = strPos;
            }
        }


        $(document).ready(function () {

            if ($.cookie("scriptExecuted") != "yes") {
                //Scroll div you the bottom onpage load
                $("#scrollArea").scrollTop($("#scrollArea")[0].scrollHeight);

                $.cookie("scriptExecuted", "yes");
            }
        });
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
    &lt;div id="scrollArea" style="overflow-y: scroll; height: 260px; width: 300px" onscroll="javascript:SetDivPosition();"&gt;
      This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;
        This is some text.&lt;br /&gt;



    &lt;/div&gt;
    &lt;asp:Button Text="Submit" runat="server" /&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>