簡體   English   中英

如何在asp.net中將數據實時分配給控件

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

我具有將顯示100000條消息的轉發器控件,我不想使用不同的頁面向用戶顯示所有消息。相反,我想在用戶向下滾動時加載,而不是在一個頁面中加載所有消息時間。

例如:Facebook時間軸。

謝謝

編輯:我試過的:

<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>

背后的代碼

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();  
        }
    }

但是我想使用更復雜的控件,就像您在Facebook,評論,圖片等中看到的那樣。

這將是一個很大的挑戰,因為您需要重新綁定轉發器控件以顯示其他消息。

您可以將轉發器嵌入UpdatePanel中,並在用戶到達消息末尾時重新綁定。 但是,您希望顯示的消息越多,檢索到的內容就越多,並且重新渲染所需的時間也就越長。 因此可能會有明顯的滯后。

相反,您可能想使用jQuery或支持Ajax的其他框架來在每次想添加更多消息並將其添加到頁面時從服務器獲取另一條消息,而不用重新渲染整個消息轉發器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM