Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have a page with header and footers. in body area I have a div with <asp:DataList> control. In this control I load the data. Since my data is too huge it takes time to load all the data at the same time. I want to bind first 25 records,as the user scrolls down the records needs to be rendered. When I use $(window).scroll(function() function it gets called when the user comes down to the bottom of the window. I need to call this function as my main div gets crosses. Which means to say when the Footer area starts. How to implement this in ASP.net. Please help me with the sample code.
Posted

1 solution

You can do that by using jQuery.Check below mentioned links for more info.

$(document).ready(function () {

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

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

            success: function (msg) {
                $("#myDiv").append(msg.d);
            },

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


C#
$(window).scroll(function () {
   if ($(window).scrollTop() == $(document).height() - $(window).height()) {
       sendData();
   }
});


C#
success: function (msg) {
    $("#myDiv").append(msg.d);
},



Load data dynamically on page scroll using jQuery

LOAD DATA WHILE SCROLLING PAGE DOWN WITH JQUERY
 
Share this answer
 
v3
Comments
sacraj 16-Nov-13 4:45am    
Yes the above code works fine. But I need to call $(window).scroll(function () when the user scrolls down after my body area or body div. When the user scrolls down the page to Footer div The window.scroll function should be called. But this function is getting called when the user scrolls down the page till the end.
Sampath Lokuge 16-Nov-13 5:03am    
OK then you can use your footer's div id instead of '$(window)' and try it (replace it with your div id).
sacraj 17-Nov-13 23:52pm    
I have replaced $(window) with $("#FooterDiv"). But it is not working for me.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900