Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:36:50+00:00 2026-06-02T22:36:50+00:00

In my ASP.Net page, I am loading data from server while scrolling using jQuery

  • 0

In my ASP.Net page, I am loading data from server while scrolling using jQuery AJAX. I am using this method since loading data from the server using AJAX will help any application in improving its performance because data which is displayed on the screen alone is loaded the first time and more data, if required, will get loaded from the server as the user scrolls. I am using the following code:

$(document).ready(

        function () {
            $contentLoadTriggered = false;
            $(window).scroll(

            function () {
                if ($(window).scrollTop() >= ($("#wrapperDiv").height() - $(window).height()) && $contentLoadTriggered == false) { //here I want to check for the isReady variable in ViewState
                    $contentLoadTriggered = true;
                    $.ajax({
                        type: "POST",
                        url: "MyPage.aspx/GetDataFromServer",
                        data: "{}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        async: true,
                        cache: false,
                        success: function (msg) {
                            $("#wrapperDiv").append(msg.d);
                            $contentLoadTriggered = false;
                        },
                        error: function (x, e) {
                            alert("The call to the server side failed. " + x.responseText);
                        }
                    });
                }
            });
        });

[WebMethod]
public static string GetDataFromServer()
{
    string resp = string.Empty;
    for (int i = 1; i <= 10; i++)
    {
        resp += "<p><span>" + i + "</span> This content is dynamically appended to the existing content on scrolling.</p>";
    }

    //if (myConidition)
        //ViewState["isReady"] = true;

    return resp;
}

At some point (when my condition is met), I want to stop loading data from the server. So I thought about setting a boolean variable isReady in the ViewState and then check the value of this variable in jQuery to determine whether or not to call the WebMethod. Unfortunately, I can’t use ViewState in WebServices and I also don’t know how to access ViewState in jQuery.

What can I use as an alternative to ViewState, which can be accessed from both the WebMethod and the jQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:36:51+00:00Added an answer on June 2, 2026 at 10:36 pm

    The best way i can think of is to send a custom class object or string [];

    Public class CustomClass
    {
        public string HTML { get; set; }
        public bool Load  { get; set; }
    }
    
    [WebMethod()]
    public static StatusViewModel  GetDataFromServer()
    {
        // do work
        return CustomObject;
    }
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery in my ASP.NET MVC 2 page. It's a super simple post
I have an ASP.NET page that requires data from another DLL and the process
I've got this textBox which triggers off an ajax request using jQuery: <asp:TextBox ID=postcodeTextBox
I have a classic ASP page which is loading an ASP.net page through an
I'm writing a pretty complex web form using ASP.NET Dynamic Data. Several of the
I'm using ephtmltopdf dll to convert an html page into pdf.I'm loading a data
I posed a question that related where I could display Page loading in asp.net
I am Developing a web application by using ASP.NET 3.5, jQuery and RadAjax Telerik
I have a number of asp.net AJAX update panels on a page, that can
This is NOT a Master/Detail question. I am using ASP.Net MVC and trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.