Ajax Problem: UpdatePanel with dropdownlist jumps to bottom of the page

Discussion in 'ASP .Net' started by retroman80s, Mar 3, 2007.

  1. retroman80s

    retroman80s Guest

    I have an UpdatePanel with a DropDownList. Everytime I select a new
    item on the DropDownList, the UpdatePanel refreshes and the page jumps
    to the bottom. I want it to go back to the top of the page, any ideas
    what the problem is?


    Everything ASP.NET 2.0
    ------------------------------------
    http://funkylist.com/ViewList.aspx?id=64&name=Everything ASP.NET 2.0
     
    retroman80s, Mar 3, 2007
    #1
    1. Advertising

  2. retroman80s

    Kevin Guest

    Yep, by default ASP.NET AJAX retains the current document scroll
    position (which is a good thing since 95% of the time end users would
    want that). In your case, you can wire the endRequest event of the
    AJAX request and scroll to top using something similar to:

    <asp:ScriptManager ID="ScriptManager1" runat="server"
    EnablePartialRendering="true"/>

    <script type="text/javascript">


    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(OnEndRequest);

    function OnEndRequest(sender,args)
    {
    window.scrollTo(0,0);
    }
    </script>

    Just make sure the javascritp code is below ScriptManager tag
    (otherwise a javascript not defined error will occur)
     
    Kevin, Mar 3, 2007
    #2
    1. Advertising

  3. retroman80s

    retroman80s Guest

    On Mar 3, 11:35 am, "Kevin" <> wrote:
    > Yep, by default ASP.NET AJAX retains the current document scroll
    > position (which is a good thing since 95% of the time end users would
    > want that). In your case, you can wire the endRequest event of the
    > AJAX request and scroll to top using something similar to:
    >
    > <asp:ScriptManager ID="ScriptManager1" runat="server"
    > EnablePartialRendering="true"/>
    >
    > <script type="text/javascript">
    >
    > var prm = Sys.WebForms.PageRequestManager.getInstance();
    > prm.add_endRequest(OnEndRequest);
    >
    > function OnEndRequest(sender,args)
    > {
    > window.scrollTo(0,0);
    > }
    > </script>
    >
    > Just make sure the javascritp code is below ScriptManager tag
    > (otherwise a javascript not defined error will occur)



    Thanks Kevin for replying. It work great in IE, but in firefox the
    first time you try it, it still jumps to the bottom of the page. The
    funny thing is that the second and other times you try it, it works.
    Any ideas why it doesn't go to the top the first time the page loads?

    Thanks

    Everything ASP.NET 2.0
    ------------------------------------
    http://funkylist.com/ViewList.aspx?id=64&name=Everything ASP.NET 2.0
     
    retroman80s, Mar 5, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Knoop

    Postback jumps to different page

    John Knoop, Jun 27, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    480
    andrei
    Jun 27, 2003
  2. Noozer
    Replies:
    1
    Views:
    7,249
    Carolyn Marenger
    Mar 13, 2006
  3. =?Utf-8?B?Vk1J?=

    radioButton change jumps to top of page?

    =?Utf-8?B?Vk1J?=, Aug 1, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    589
    =?Utf-8?B?Vk1J?=
    Aug 1, 2006
  4. dbuchanan
    Replies:
    1
    Views:
    295
    Charles Wang [MSFT]
    Jun 20, 2008
  5. cmeek1_1999
    Replies:
    3
    Views:
    4,896
    cmeek1_1999
    Sep 27, 2008
Loading...

Share This Page