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

  • Home
  • SEARCH
  • 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 8326061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:38:44+00:00 2026-06-09T00:38:44+00:00

i have a webmethod that call it by jquery ajax .in web method i

  • 0

i have a webmethod that call it by jquery ajax .in web method i bind repeater data source to pagedatasourse object but when i run my program if i dont use of static key word webmethode before method name jquery ajax method dose not work properly and if use static keyword i have this error

Object reference not set to an instance of an object….System.NullReferenceException: Object reference not set to an instance of an object.

and pagedatasourse fall in exception.i confused.what is solution?
thank you very much
its my jquery function

 $(function () {
            var x = 0;
            $('.c1').bind('click', function () {

                counter = counter + 1;
                $.ajax(
                {
         type: "POST",
            url: "WebForm1.aspx/bringdata",
      data: { counter: counter },
          contentType: "application/json; charset=utf-8",
           dataType: "json",
           async: true,
            cache: false,
              success: function (ret) {

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

            })
            $('.c2').bind('click', function () {

                x = x - 1;

            })

        })

and its code behind :

  [WebMethod]
  public  static void bringdata(int counter){
   SqlConnection con = new SqlConnection("data source=.;database=site;integrated   security=true;");
   int cnt;
   string sSQL = "Select username ,average,weight,point,password ,kal, Rank() over(order    by point desc) as 'ranking' from karbar order by point desc";  
   SqlCommand cmd = new SqlCommand(sSQL, con);  

   SqlDataAdapter adapt = new SqlDataAdapter(cmd);
   DataSet ds = new DataSet();
   adapt.Fill(ds);
   cnt=ds.Tables[0].Rows.Count;
   PagedDataSource pds = new PagedDataSource();
   pds.AllowPaging=true;
   pds.DataSource=ds.Tables[0].DefaultView;
   pds.PageSize=5;
   pds.CurrentPageIndex=counter;
   int vcnt=cnt/pds.PageSize;
   rptList.DataSource = pds;  
   rptList.DataBind(); 

}

  • 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-09T00:38:45+00:00Added an answer on June 9, 2026 at 12:38 am

    Why you get exception?

    My guess would be, because APS.NET disposes the DataSet (not seen here) after each request, while you are trying to page results from the previous request. If you make a DataSet static (it’s a big no-no in ASP.NET) then it is kept in the memory and is also shared between all the requests.

    How to fix this?

    You are using incorrect data access pattern. Datasets are really fat bad boys and practically should not be used with ASP.NET.

    • Get rid of the DataSet completely. Do not use static objects, when you get some traffic to your application you will see real weird bugs.
    • Use something more lightweight, like List<Record> and populate it with DataReader.
    • Use database paging, instead of in-memory paging. Never ask database server to bring all the data, or else your app will go down (when you get some traffic and database becomes larger).
    • Consider using ORM (like NHibernate or EF), it will do a lot of magic for you.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webmethod that returns a Hashtable through a jQuery ajax call along
I have a c# web service that I call using jquery ajax. It works
I have a jquery ajax call asp.net web service but it is not working.
i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
I have a web service that has one method: [WebMethod] public bool SyncUserData(string userxml)
I have a jquery Ajax call function that I use to submit form to
Within a web form I have the following jQuery setup to call a method
I have an asp.net WebMethod that returns an XmlDocument object. I can successfully call
Is it possible in jax-ws to have a webmethod that creates a new object
I have a web method that returns a String[][] and I'm trying to parse

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.