Click here to Skip to main content
13,142,065 members (56,054 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 27 Mar 2014

Server Side Parameterized Method Call Using JQuery

, 27 Mar 2014
Rate this:
Please Sign up or sign in to vote.
This demo shows how jquery calls the server side parameterized method.


This is a C# project that demonstrates how client side scripting language (JQuery) is used to call server side parameterized method that is written in server side language (C#, VB).

Using the Code

Step 1

WebForm1.aspx page has some controls like button, textbox control. Textbox is used to get a message from client to pass it to server side method. On button click, div element shows the message received from server.

<form id="form1" runat="server">
            <asp:TextBox ID="Text1" runat="server" />
            <asp:Button ID="Button1" runat="server" Text="ClickMENow" />
            <br />
            <div id="myDiv"></div>

Step 2

Use the following JQuery to make Ajax call to server side method:

<script src="//"></script>
<script src="//"></script>
        $(document).ready(function () {
            $('#<%=Button1.ClientID %>').click(function () {
                    type: "POST",
                    url: "WebForm1.aspx/ServerSideMethod",
                    data: JSON.stringify({ 'p': $('#Text1').val() }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    async: true,
                    cache: false,
                    success: function (msg) {

                    error: function (x, e) { alert(x.responseText); }
                return false;

Step 3

Server side method in WebForm1.aspx.cs is followed by WebMethod attribute:

public static string ServerSideMethod(string p)
    return "Message from Server"+p ;

Points of Interest

The server side method must be static and prefixed by attribute [WebMethod].


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Manoj Kr. Verma
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionMy vote 5 Pin
Chakravarthi Elchuri10-Jul-14 21:47
professionalChakravarthi Elchuri10-Jul-14 21:47 
AnswerRe: My vote 5 Pin
Manoj Kr. Verma16-Jul-14 2:28
professionalManoj Kr. Verma16-Jul-14 2:28 
QuestionWorks in IE Not in Chrome Pin
Grant Fletcher3-Apr-14 9:37
memberGrant Fletcher3-Apr-14 9:37 
QuestionIt's not working Pin
ntuthuko-m28-Mar-14 3:05
memberntuthuko-m28-Mar-14 3:05 
AnswerRe: It's not working Pin
Manoj Kr. Verma13-Nov-14 2:35
professionalManoj Kr. Verma13-Nov-14 2:35 
GeneralMy vote of 1 Pin
PBGuy27-Mar-14 23:04
professionalPBGuy27-Mar-14 23:04 
GeneralToo Rudimentary Pin
b-rad_mt27-Mar-14 12:18
memberb-rad_mt27-Mar-14 12:18 
QuestionGreat Post Pin
KentsCode27-Mar-14 2:15
memberKentsCode27-Mar-14 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170915.1 | Last Updated 27 Mar 2014
Article Copyright 2014 by Manoj Kr. Verma
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid