Keep DataGrid visible after Changing the PageIndex

Hi all!!!

I have a webform that show a pageable datagrid.

To access the DataGrid's footer, i need to scroll down the page. When I change the current page (from 1 to 2, for example) the page is post backed, and the data e changed on the datagrid correctly. But, all the time that I datagrid's page i need to scroll down to see my data again.

I've saw some pages that have as "automaticaly scrolling" function that always return the page to the last scrolled position. So, i want to implement this on my app.

Could anybody provide me some information of how could i do this?

Thanks all!!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you can try this code...

just put it on top of ur aspx page

   Sub SmartScroller()

        Dim m_theForm = GetServerForm(Page.Controls)

        Dim hidScrollLeft As New HtmlInputHidden()
        hidScrollLeft.ID = "scrollLeft"

        Dim hidScrollTop As New HtmlInputHidden()
        hidScrollTop.ID = "scrollTop"


        Dim scriptString As String
        'scriptString += "<!-- sstchur.web.SmartNav.SmartScroller ASP.NET Generated Code -->" + Chr(13)
        scriptString += "<script language = ""javascript"">" + Chr(13)
        scriptString += "<!--" + Chr(13)
        scriptString += "    function sstchur_SmartScroller_GetCoords()" + Chr(13)
        scriptString += "  {" + Chr(13)
        scriptString += "    var scrollX, scrollY;" + Chr(13)
        scriptString += "        if (document.all)" + Chr(13)
        scriptString += "    {" + Chr(13)
        scriptString += "            if (!document.documentElement.scrollLeft) {" + Chr(13)
        scriptString += "        scrollX = document.body.scrollLeft; }" + Chr(13)
        scriptString += "            else {" + Chr(13)
        scriptString += "        scrollX = document.documentElement.scrollLeft; }" + Chr(13)
        scriptString += "" + Chr(13)
        scriptString += "                if (!document.documentElement.scrollTop) {" + Chr(13)
        scriptString += "        scrollY = document.body.scrollTop; }" + Chr(13)
        scriptString += "                else {" + Chr(13)
        scriptString += "        scrollY = document.documentElement.scrollTop; }" + Chr(13)
        scriptString += "    }" + Chr(13)
        scriptString += "    else" + Chr(13)
        scriptString += "    {" + Chr(13)
        scriptString += "      scrollX = window.pageXOffset;" + Chr(13)
        scriptString += "      scrollY = window.pageYOffset;" + Chr(13)
        scriptString += "    }" + Chr(13)
        scriptString += "    document.forms[""" + m_theForm.ClientID + """]." + hidScrollLeft.ClientID + ".value = scrollX;" + Chr(13)
        scriptString += "    document.forms[""" + m_theForm.ClientID + """]." + hidScrollTop.ClientID + ".value = scrollY;" + Chr(13)
        scriptString += "  }" + Chr(13)
        scriptString += "" + Chr(13)
        scriptString += "" + Chr(13)
        scriptString += "  function sstchur_SmartScroller_Scroll()" + Chr(13)
        scriptString += "  {" + Chr(13)
        scriptString += "    var x = document.forms[""" + m_theForm.ClientID + """]." + hidScrollLeft.ClientID + ".value;" + Chr(13)
        'scriptString += "  alert(x);" + Chr(13)
        scriptString += "    var y = document.forms[""" + m_theForm.ClientID + """]." + hidScrollTop.ClientID + ".value;" + Chr(13)
        scriptString += "    window.scrollTo(x, y);" + Chr(13)
        scriptString += "  }" + Chr(13)
        scriptString += "" + Chr(13)
        scriptString += "" + Chr(13)
        scriptString += "  window.onload = sstchur_SmartScroller_Scroll;" + Chr(13)
        scriptString += "  window.onscroll = sstchur_SmartScroller_GetCoords;" + Chr(13)
        scriptString += "  window.onclick = sstchur_SmartScroller_GetCoords;" + Chr(13)
        scriptString += "  window.onkeypress = sstchur_SmartScroller_GetCoords;" + Chr(13)
        scriptString += "// -->" + Chr(13)
        scriptString += "</script>" + Chr(13)
        scriptString += "<!-- End sstchur.web.SmartNav.SmartScroller ASP.NET Generated Code -->" + Chr(13)
        Page.RegisterStartupScript("SmartScroller", scriptString)

    End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
its not suppose to be aspx page but code behind... sry
then... put this addition code in ur page_load

Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

wat it does is that... everytime u click the combo box to change the paging... it will return back to the scroll area....

its pretty cool...
That's pretty nifty entrapnet, did some research on it, actually comes in a control, where you can do some more things with it,

smartscroller will work the same but if i'm not mistaken, the javascript that i used to obtain will solve the problem for different type of browsers.
I'll be sure to give it a run through in the morning when I get back to work, in the past I had rigged up some code using scrollIntoView() but this definitely seems more robust.  It's a nice alternative to the usual "Just set smartnavigation=true" answer I see all the time!
thx for the compliment... hope u like it...
regisdanielAuthor Commented:
Thanks raterus and entrapnet!!!!

I will try the both solutions to see what works better.

But, raterus, i trying to download the SmartScroller, but the server appears in problem. Could you please send the file to my mail?
If yes, my mail is **email removed by raterus**

Thanks everyone for all the answers!!!

If you give points to anyone, give it to entrapnet, I just merely added on to his solution.  I actually haven't tried out that control yet, but I do see your problem.  Sorry can't email it to you since I don't have it.  I imagine other versions are out there somewhere.

regisdanielAuthor Commented:
Ok!!! No problem!!!

I trying to use the method send by entrapnet , but my system is not able to find a reference to 'GetServerForm' method. How could i solve this?
   Function GetServerForm(ByVal parent As ControlCollection) As HtmlForm
        Dim child As Control
        For Each child In parent
            Dim t As Type = child.GetType()
            If t.ToString = "System.Web.UI.HtmlControls.HtmlForm" Then
                Return child
            End If

            If child.HasControls() Then
                Return GetServerForm(child.Controls)
            End If
        Return New HtmlForm()
    End Function
sry... forget to post that....
GetServerForm is to get the form name...

<form id="myNameisHere" <-->
Are you looking for something that uses SmartNavigation (the page returns to the same place on the page after a postback)?

Check this control out.  It's cross browser as well

in the top of the HML code, in the yellow header, place SmartNavigation = "True"

Note that you have to set SmartNavigation = "False" in the code behind before you use Response.Redirect() or else you will have problems like I had.  Just stick it on the line before the redirect and you'll be fine.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.