-3

I have developed a 90,000 lines of code C# application, with ASP.NET front end code and MS SQL Server database tables. When I select any choice from the dropdown lists and click search, it searches the database and binds the results to the front end in a grid view.

The code works perfectly, however after the data binding there is only one problem and that is that it returns to the top of the page again and it is inconvenient for the user as they must scroll back down again. I am sure many of you have had this problem when you were beginners like me. It actually goes back to the top after every single data bind from any dropdown list and this makes it very inconvenient to use. Can anyone help me with this?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Soliman Soliman
  • 159
  • 1
  • 4
  • 17

1 Answers1

0

I'm guessing you are using Webforms? It has to do with post back, every time you perform some kind of action in the page, the page data is posted to the server and then the page is reloaded with the results of that action. When the page is reloaded it goes back to the top.

There are several ways to avoid this. All involves calling the server in the background and updating the page when the call returns, without reloading the page. You could for instance use an UpdatePanel: https://msdn.microsoft.com/en-us/library/bb399001.aspx or use client-side javascripts to make calls to the server in the background.

Håkan Fahlstedt
  • 2,040
  • 13
  • 17
  • Thanks for the extra insight about why this happens Hakan. The simple answer of adding MaintainScrollPositionOnPostback = "true" to my page directive worked for me. Although this meant I had to change many page directives to add this setting, it works. So there is no need to further complicate life unnecessarily. – Soliman Soliman Jul 13 '16 at 06:55