Smooth horizontal page scrolling with ASP.NET Button and JQuery

Posted: September 9, 2010 in ASP.NET

Hi all,

In one of my projects I just had to come over a requirement where I have a search page with a search button and a gridview control which displays the search results. The search criteria list is a long one so, when the user clicks the search button, he/she may not even know that results have been displayed or not unless he/she scrolls down the page. In this example, I have the code for displaying the search results in button’s click event. So when the user clicks the button, the grid will get filled with the results and also a smooth scrolling is made to the position where the grid is placed.

For the above, you have just include these JQuery files.
http://code.jquery.com/jquery.min.js
http://gsgd.co.uk/sandbox/jquery/easing/

After including these files, just put the following code in the Page_Load
btnSearch.Attributes.Add("onclick", " $('html, body').stop().animate({scrollTop: $('#divCandidate').offset().top}, 5000, 'easeInOutExpo');;return true;");

In the above code “divCandidate” is the div in which the gridview is residing. 5000 is the scrolling time interval.

Also, make sure the criteria list (most probably, a table containing some controls) and the gridview are resided in an update panel.

Happy Scrolling!!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s