Click here to Skip to main content
13,459,013 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 13 Mar 2012

Load data dynamically on page scroll using jQuery, AJAX, and ASP.NET

, 6 Sep 2012
Rate this:
Please Sign up or sign in to vote.
Load data dynamically on page scroll.


In Facebook you might see status updates of your friends dynamically loaded when you scroll the browser’s scroll bar. In this article I am going to explain how we can achieve this using jQuery and AJAX. 

Using the code

The solution includes two web forms (Default.aspx and AjaxProcess.aspx). The Default.aspx contains a Div with ID myDiv. Initially the Div contains some static data, then data is dynamically appended to it using jQuery and AJAX. 

<div id="myDiv">
	<p>Static data initially rendered.</p>

The second Web Form AjaxProcess.aspx contains a web method GetData() that is called using AJAX to retrieve data.

public static string GetData()
    string resp = string.Empty;
    resp += "<p>This content is dynamically appended to the existing content on scrolling.</p>";
    return resp;

Now we can add some jQuery script in Default.aspx that will be fired on page scroll and invokes the GetData()method.

$(document).ready(function () {

   $(window).scroll(function () {
       if ($(window).scrollTop() == $(document).height() - $(window).height()) {

   function sendData() {
            type: "POST",
            url: "AjaxProcess.aspx/GetData",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: "true",
            cache: "false",

            success: function (msg) {

            Error: function (x, e) {
                alert("Some error");

Here, to check whether the scroll has moved to the bottom, the following condition is used.

$(window).scroll(function () {
   if ($(window).scrollTop() == $(document).height() - $(window).height()) {

This condition will identify whether the scroll has moved to the bottom or not. If it has moved to the bottom, dynamic data will get loaded from the server and get appended to myDiv.

success: function (msg) {


Version 1.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

vivek poomala
Web Developer Teknokraaft info systems
India India

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Member 1169020214-Oct-15 20:46
memberMember 1169020214-Oct-15 20:46 
Questiondata loss when press back button of browser Pin
Shrikrushna S. Ingle19-Aug-13 19:35
memberShrikrushna S. Ingle19-Aug-13 19:35 
GeneralMy vote of 4 Pin
kumarvinodh24-May-13 23:36
memberkumarvinodh24-May-13 23:36 
QuestionThanks Pin
Member 327776022-May-13 3:25
memberMember 327776022-May-13 3:25 
GeneralMy vote of 3 Pin
bhargavpp17-Sep-12 19:36
memberbhargavpp17-Sep-12 19:36 
Question[My vote of 1] kill me with a blunt knife, please... Pin
Seishin#13-Mar-12 22:19
memberSeishin#13-Mar-12 22:19 
AnswerRe: [My vote of 1] kill me with a blunt knife, please... Pin
vivek poomala14-Mar-12 1:16
membervivek poomala14-Mar-12 1:16 
GeneralRe: [My vote of 1] kill me with a blunt knife, please... Pin
Dewey10-Sep-12 7:03
memberDewey10-Sep-12 7:03 
AnswerRe: [My vote of 1] kill me with a blunt knife, please... Pin
komaliShiru1-Aug-12 21:44
memberkomaliShiru1-Aug-12 21:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180323.1 | Last Updated 6 Sep 2012
Article Copyright 2012 by vivek poomala
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid