简体   繁体   中英

How to assign the data to controls on fly in asp.net

i have repeater control which will display a 100000 messages, i don't want to use different pages to show all the messages to the user.. Instead i want to load the while the user scrolls down, rather then loading all the messages in one time.

As an example: Facebook timeline.

thanks

Edited : what i tried :

<script type="text/javascript">
        $(document).ready(function e() {
            $(window).scroll(function () {
                if ($(window).scrollTop() == $(document).height() - $(window).height()) {
                    GetRecords();
                }
            });

            function GetRecords() {
                $("#loader").show();
                $.ajax({
                    type: "POST",
                    url: "Demo.aspx/GetList",
                    data: {},
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    failure: function (response) {
                        alert("Failure");
                    },
                    error: function (response) {
                        alert("Error");
                    }
                });
            }

            function OnSuccess(response) {
                $.map(response.d, function (item) {
                    $('#division').append("<div style='line-height:25px;'>" + item + "</div>");
                });
                $("#loader").hide();
            }
        });
    </script>

code behind

public partial class Demo : System.Web.UI.Page
    {                     
        static List<string> list = new List<string>();
        static int n=0;

        protected void Page_Load(object sender, EventArgs e)
        {
            n = 0;
        }

        public Demo()
        {
            for (int i = 1; i <= 1000; i++)
            {
                list.Add("List Item : " + i);
            }
        }

        [WebMethod]
        public static List<string> GetList()
        {
            var fiftyItems = list.Skip(n).Take(50);
            n = n + 50;
            return fiftyItems.ToList();  
        }
    }

but i want to work with more complected control , something like you saw in facebook, comments, pictures, etc..

That's going to be quite a challenge, because you need to re-bind the repeater control to show additional messages.

You could embed the repeater in an UpdatePanel and rebind as the user reaches the end of the messages. But the more messages you want to show, the more you'll have to retrieve and the longer it will take to re-render. So there might be a noticable lag.

You might instead want to use jQuery or another framework that supports Ajax to grab another chunk of messages from the server every time you want to add more, and add those to your page, without re-rendering the entire repeater full of messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM