Click here to Skip to main content
11,929,944 members (51,982 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked

Asychronous Web Service Call

, 21 Feb 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Asynchronous Web Service Call


This tip gives us an idea to call methods of page in an asynchronous way.


To call method asynchronously, AJAX has to provide build ins example $.ajax( ).

Using the Code

Step 1

Create a simple AsychCall web page (.aspx). Create a web method, which we need to consume asynchronously like:

public static bool ExecuteReport(string reportingYear )
    bool returnvalue = true;
    int reportReturnValue = -1;
        reportReturnValue = GenerateReport.ReportGeneratereportingYear 
        if (reportReturnValue == -1)
            return false;
        return returnvalue;
    catch (System.Exception ex)
        return returnvalue;

Step 2

Create another webpage and place a button like:

     <asp:Panel ID="pnlReportStatusMsg" 
                runat="server" Visible="true">
         <input type="button" id="btnReportGenerate" 
                    value="Generate Report" onclick="executeReport();"
                        runat="server" />

Step 3

On the button click, call a JavaScript method "executeReport(); like:

       type: "POST",
       url: "/AsychCall.aspx/ExecuteReport",
       data: "{reportingYearKey:'" + FiscalYearValue }",
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (msg) {
           if (msg.d == false) {
               document.getElementById('<%= lblReportStatus.ClientID %>').
               style.display = 'block';
               $("#<%=lblReportStatus.ClientID %>

Step 4

Compile this code. You see, when you click the button "Generate Report", AJAX method asynchronously calls Web method "ExecuteReport" from AsychCall Web page.


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


About the Author

Pathak Ashwin
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionSince this is specifically about async Pin
Marcus Kramer15-Feb-13 12:02
mvpMarcus Kramer15-Feb-13 12:02 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 21 Feb 2013
Article Copyright 2013 by Pathak Ashwin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid