Page done loading scroll to top

Posted on 2011-05-03
Last Modified: 2012-05-11
When the page is done loading, I want to scroll to the top of the page.

Is there Javascript for this?

Please provide source code.
Question by:knowlton
    LVL 8

    Assisted Solution

    Yes.  You can place Javascript as the last line in the html form.

    <script type="text/javascript" language="javascript">
    LVL 5

    Author Comment

    What if the page is a content page with a master page in

    Where does the javascript go?
    LVL 5

    Author Comment

    I should mention that what seems to be causing this problem is an iframe.

    When the src for the iframe changes to another URL....the entire page scrolls down.
    LVL 8

    Expert Comment

    Can you share your code?
    LVL 14

    Accepted Solution


    will it be a soln for u?

    Page.MaintainScrollPositionOnPostBack = True
    LVL 5

    Author Comment

    >>>Page.MaintainScrollPositionOnPostBack = True

    Did not change the behavior.

    Here is my code:

    Master Page:
    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="TCSSite.Master.cs" Inherits="Campus_Webstore.SiteWideMaster.TCSSiteUCONN" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    <%@ Register Src="~/UserControls/TopCart.ascx" TagName="TopCart" TagPrefix="uc1" %>
    <%@ Register Src="~/UserControls/usertop.ascx" TagName="usertop" TagPrefix="uc2" %>
    <%@ Register Src="~/UserControls/Catalogs.ascx" TagName="Catalogs" TagPrefix="uc3" %>
    <%@ Register src="../../UserControls/HorizMenu.ascx" tagname="HorizMenu" tagprefix="uc5" %>
    <%@ Register src="../../UserControls/AccordionNav.ascx" tagname="AccordionNav" tagprefix="uc4" %>
    <%@ Register Src="~/UserControls/gentoplogin.ascx" TagName="Login1" TagPrefix="uc10" %>
    <%@ Register Src="~/UserControls/HuskyFooter.ascx" TagName="HuskyFooter" TagPrefix="uc11" %>
    <%@ Register assembly="Campus Webstore" namespace="Campus_Webstore" tagprefix="cc1" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head id="Head1" runat="server">
    <title>UConn Co-op Husky Shop</title>
        <link href="~/Scripts/jquery.superbox.css" rel="stylesheet" type="text/css" />
        <link href="~/App_Themes/uconn/cws2.css" rel="stylesheet" type="text/css" />
        <link href="~/App_Themes/uconn/uconn.css" rel="stylesheet" type="text/css" />
        <link href="~/Scripts/allclients.css" rel="stylesheet" type="text/css" />
        <link href="../../App_Themes/uconn/addoredit_control.css" rel="stylesheet" type="text/css" />
        <link href="../../App_Themes/uconn/addoredit_popupstyling.css" rel="stylesheet" type="text/css" />
        <link href="../../App_Themes/uconn/shippingmethodstyling.css" rel="stylesheet" type="text/css" />
        <link href="../../App_Themes/uconn/orderdonestyling.css" rel="stylesheet" type="text/css" />
        <link href="../../App_Themes/uconn/securepaymentpagestyling.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src=""></script>
        <script type="text/javascript" src="../../Scripts/jquery-1.4.1.js"></script>
        <script src="../../Scripts/husky_top_menu.js" type="text/javascript"></script>
        <script src="../../EFUImageUploader/efu-js/easyflashuploader.js" type="text/javascript"></script>
        <script src="../../EFUImageUploader/efu-js/language.en.js" type="text/javascript"></script>
        <link rel="SHORTCUT ICON" href="../../favicon.ico" />
        <%-- <link rel="shortcut icon" href="../App_Themes/SkinFile/Images/favicon.ico" type="image/" />--%>
    <!-- ******** BEGIN LIKNO WEB ACCORDION CODE FOR likno_accordion_project ******** -->
    <%--<script type="text/javascript">    
    var lwacLinkedBy = "LiknoWebAccordion [1]", lwacName = "likno_accordion_project", lwacBN = "126";
    <script charset="UTF-8" src="../../Scripts/likno_accordion_project.js" type="text/javascript"></script>--%>
    <!-- ******** END LIKNO WEB ACCORDION CODE FOR likno_accordion_project ******** -->
    <script type="text/javascript">
        window.scroll(0, 0);
        function CheckForFrameChange()
            var theframe = document.getElementById("ccinfo");
            strURL = theframe.src;
            //setup a pointer to the begining of the /photos/ part of the string
            var hasit = strURL.indexOf('ElementPSResults');
            if (hasit > 0)
                var theHTML = document.getElementById("ccinfo").contentWindow.document.body.innerHTML;
                if (theHTML.indexOf('veryobviousSuccess') > 0)
                    alert("Suceess was found");
               // CheckForFrameChange();
    <body id="bodytaguconn" runat="server">
        <form id="mainbodyformuconn" runat="server">
        <ajaxToolkit:ToolkitScriptManager runat="server" ID="toolKit" AllowCustomErrorsRedirect="true"
                <%-- <script type="text/javascript" src=""></script>
    			<script language="javascript" type="text/javascript">
    				google.load("jquery", "1");
                <atlas:ScriptReference Path="~/scripts/thickbox.js" />
                <atlas:ScriptReference Path="~/scripts/contact.js" />
    <div id="W" class="W">
    <div id="C" class="C">
    <div id="C1" class="C1"></div><%--end div c1--%>
    <div id="O" class="O">
    <div id="S" class="S"><uc10:Login1 ID="Login1" runat="server" /></div><%--end div s--%>
    </div><%--end div o--%>
    <div id="Y" class="Y">
    <div id="V" class="V"></div><%--end div v--%>
    <div id="P" class="P">
    <cc1:themeawareimage ID="ThemeAwareImage2" runat="server" 
            ImageUrl="new_header_angled2.png" />
    </div><%--end div p--%>
    <div id="U" class="U">
    <div id="T" class="T"><object id="searchtcsdatc" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=",0,0,0"
                width="200" height="22" align="left">
                <param name="allowScriptAccess" value="always" />
                <param name="allowFullScreen" value="false" />
                <param name="movie" value="/searchtcs.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="wmode" value="transparent" />
                <embed src="/searchtcs.swf" id="searchtcsdatcembed" quality="high" bgcolor="#ffffff"
                width="200" height="22" name="searchtcsdatcsname" align="left" allowscriptaccess="always"
                allowfullscreen="false" wmode="transparent" type="application/x-shockwave-flash"
                pluginspage="" />
    </div><%--end div t--%>
    <div id="X" class="X"><uc1:TopCart ID="TopCartHusky" runat="server" /></div><%-- end div x --%>
    </div><%--end div u--%>
    </div><%--end div y--%>
    <div id="Z" class="Z">
    <div id="N" class="N">
    <%--end div n--%>
    <div id="R" class="R">
    <uc5:HorizMenu ID="HorizMenu1" runat="server" />
    </div><%--end div r--%>
    </div><%--end div z--%>
    </div><%--end div c--%>
    <div id="A1" class="A1">
    <div id="E" class="E">
    <div id="F" class="F"><cc1:themeawareimage ID="husky_dog" 
            runat="server" ImageUrl="husky-dog.png" /></div><%--end div f--%>
    <div id="G" class="G">
    <uc3:Catalogs runat="server" ID="Catalogs1" />
    </div><%--end div g--%>
    </div><%--end div e--%>
    <div id="D" class="D">
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>    
    </div><%--end div d--%>
    <div id="H" class="H">
    <div id="I" class="I"></div><%--end div i--%>
    <div id="B1" class="B1">
    <div id="J" class="J"><uc11:HuskyFooter ID="HF" runat="server" /></div><%--end div j--%>
    <div id="K" class="K">
    <%--<div id="footer">
    <div class="content">
    <div class="footer_r">
    <a href="">UConn Co-op Bookstore</a> &nbsp;·&nbsp;Phone:
    (860) 486-3537<br />
    Questions: <a href="">Co-op Help/Info</a><br />
    Webmaster:<br />
    <div class="footer_l">
    <br />
    Powered by:<br />
    <a href="">
    Total Computing</a><br />
    <!-- END FOOTER -->
    </div><%--end div k--%>
    </div><%--end div b1--%>
    </div><%--end div h--%>
    </div><%--end div a1--%>
    </div><%--end div w--%>

    Open in new window

    content page:
    <%@ Page Title="" Language="C#" AutoEventWireup="true" CodeBehind="SecureOrderForm.aspx.cs" Inherits="Campus_Webstore.SecureOrderForm" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="AEPS" class="AEPS">
    <div id="BEPS" class="BEPS">
    <div id="CEPS" class="CEPS">
    </div><%--end of div CEPS--%>
    <div id="DEPS" class="DEPS">
    Secure Order Form
    </div><%--end of div DEPS--%>
    <div id="GEPS" class="GEPS"></div><%--end of div GEPS--%>
    </div><%--end of div BEPS--%>
    <div id="EEPS" class="EEPS">
    <div id="HEPS" class="HEPS">
    <iframe id="ccinfo" frameborder="0" style="border-width:0px;background-color:#fff;width:770px;height:400px;overflow:hidden;" runat="server" src="Blank.aspx?show=no"></iframe>                                               
    </div><%--end of div HEPS--%>
    <div id="FEPS" class="FEPS">
    <asp:Button ID="ButtonElementDoneCheck" runat="server" Text="View Order Details" 
            Height="22px" onclick="ButtonElementDoneCheck_Click" />    
    </div><%--end of div FEPS--%>
    </div><%--end of div EEPS--%>
    </div><%--end of div AEPS--%>

    Open in new window

    ccinfo is the iframe.
    LVL 5

    Author Closing Comment


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    A common challenge, or question, when working with two calendar dates is: What is the difference between the specified days? As is frequently the case, the answer is: It depends... What kind of difference do you want? Given two date obje…
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved." Ralph Waldo Emerson Introduction: One of the wonderful things about the web is that it makes it s…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now