Click here to Skip to main content
13,096,268 members (51,532 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 5 Nov 2013

Ajax Call from Master Page to webservice (asmx) through JQuery

, 5 Nov 2013
Rate this:
Please Sign up or sign in to vote.
This tip describes the steps to access server side web service (asmx) from master page JavaScript.


This tip describes the steps to access server side web service (asmx) from master page JavaScript. This can be helpful in situations when you want to prevent full page postback and need to communicate from client side to server side from master page.

Using the Code

You need to follow the steps given below:

  1. Add webservice (asmx file) that contains the server side function you want to access from jquery:
        public string HelloWorld(int Variable1, string Variable2)
            return "Hello World";
  2. Uncomment the line to allow access to webservice from JavaScript:
  3. Add master page and add the markup after the form tag:
    <span id="ArticleContent">
    <h1>Access server side from jquery ajax from master page</h1>
    <label title="Click to access server from javascript" 
    onclick="SetTabSessionValue(12, 'Hello');">
    Click to access server from javascript</label>
  4. Add the JavaScript function that is called when you click on the label to master page. Adjust your webservice path and name accordingly (my webservice name is WSAccessMPJquery.asmx). Also adjust the path for jquery min.js.
    <script src="js/jquery-1.8.3.min.js" 
    function SetTabSessionValue(Variable1, Variable2) {
            var param = "{'Variable1':" + JSON.stringify(Variable1) + 
            ",'Variable2':" + JSON.stringify(Variable2) + "}";
                type: "POST",
                url: "WSAccessMPJquery.asmx/HelloWorld",
                data: param,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: SetTabSessionValueSucceed,
                error: SetTabSessionValueFailed
        function SetTabSessionValueSucceed(result) {
            alert("text from server: "+ result.d);
        function SetTabSessionValueFailed() {
            alert('call failed');
  5. Add normal aspx page that uses master page and run the solution.


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


About the Author

Muhammad Waqas Iqbal
Software Developer (Senior) Freelancer
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionThe webservice method is not executing for me Pin
yedhuvamshi9-Mar-15 20:34
memberyedhuvamshi9-Mar-15 20:34 
AnswerRe: The webservice method is not executing for me Pin
m.waqasiqbal11-Mar-15 18:48
memberm.waqasiqbal11-Mar-15 18:48 
GeneralRe: The webservice method is not executing for me Pin
yedhuvamshi11-Mar-15 19:09
memberyedhuvamshi11-Mar-15 19:09 

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.170813.1 | Last Updated 5 Nov 2013
Article Copyright 2013 by Muhammad Waqas Iqbal
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid