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 712667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:52:24+00:00 2026-05-14T04:52:24+00:00

How to call a method on a server side from JSON. Below is the

  • 0

How to call a method on a server side from JSON. Below is the code I am using

SERVER SIDE:

[WebMethod]
private void GetCustomer( string NoOfRecords)
{

    string connString = "Data Source=Something;Initial Catalog=AdventureWorks;Trusted_Connection=True;";
    SqlConnection sCon = new SqlConnection(connString);
    SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Sales.Customer WHERE CustomerID < '" + NoOfRecords+ "' ", sCon);
    DataSet ds = new DataSet();
    da.Fill(ds);
    GvDetails.DataSource = ds.Tables[0];
    GvDetails.DataBind();

}

On Client Side:

 <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
    <asp:Button ID="btnShow" runat="server" Text="Sow Records without PostBack" />

    <asp:GridView ID="GvDetails" runat="server">
    </asp:GridView>
</div>

<script language="javascript" type="text/javascript">


 var txtID = document.getElementById('txtValue');
 $.ajax({
   type: "POST",
   url: "Default.aspx/GetCustomer",
   data: "{Seconds:'" + txtID +"'}",
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   success: function(response) {
     alert(response); 
   }
  });
</script>

Now I want that on button click, I would call the function at the client side [JSON], which pass the textbox value to the function.
Please help

  • 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-05-14T04:52:24+00:00Added an answer on May 14, 2026 at 4:52 am

    It looks like you are wanting to re-bind the grid and have it update on the page. The easiest thing to do in that case, is put your button and the grid in an update panel. Give the button a server side click event. Because it is in the update panel, it will handle the ajax call for you using ajax, and the contents of the update panel will automatically update.

    If you want to do the ajax calls manuall, you won’t be able to just bind the grid like that, instead you GetCustomer method will need to return something which would get used by your client javascript. I find that rather than use $.ajax call (jquery), if you put the ScriptService tag on the method, you can make a javascript call PageMethods.GetCustomer(NoOfRecords). The javascript call syntax is exactly like the c# syntax you declared the method with, but in javascript you add “PageMethods.” in front.

    Something like this:

    Html:

    <div> 
        <asp:ScriptManager ID="ScriptManager1" runat="server"> 
        </asp:ScriptManager> 
        <asp:TextBox ID="txtValue" runat="server" CssClass="value"></asp:TextBox> 
        <asp:Button ID="btnShow" runat="server" CssClass="buttonshow" Text="Sow Records without PostBack" /> 
    
    </div> 
    
    <script language="javascript" type="text/javascript">   
    
        //attach event to click event of button with class of 'buttonshow'.
        $('.buttonshow').click(function()
        {
            //get value of textbox with class 'value'
            var NoOfRecords = $('.value').val();
    
            //Call GetCustomer method, pass NumberOfRecords, and define the onsuccess and onerror functions.
            PageMethods.GetCustomer(
                NoOfRecords, 
                function(result) {
                   alert('success:' + result);
                },
                function(result) {
                   alert('error:' + result.get_message());
                });
        });
    
    
    </script>  
    <asp:GridView ID="GvDetails" runat="server"> 
    </asp:GridView> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple WCF service that I call server side from code behind
can anybody help me to call a server side javascript method from the client
I'm trying to call a server side method, using jquery, on the textchange event
I'm trying to call a server side method from client side via jQuery. My
I'm writing a web application using python JSON-RPC implementation - http://json-rpc.org/wiki/python-json-rpc on server side
I am calling a Page Method from JQuery as described here: http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/ This is
How to send extras from server side like userId or eventId using c2dm and
Just a quick question. Say a call a method like so mysql_pconnect(server,tator_w,password) or die(Unable
I'm trying to call method from .jar But when I want to declare array
I have 2 classes 'Main' and 'FOR'. From 'Main' I will call method 'display'

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.