Click here to Skip to main content
12,688,944 members (31,483 online)
Click here to Skip to main content
Articles » Web Development » Ajax » Samples » Downloads

Stats

46.5K views
1.2K downloads
20 bookmarked
Posted

ASP.NET 3.5, AJAX, and Web Services

, 17 Mar 2008 CPOL
This article explains how to call Web Service methods using AJAX client script.
<%@ Page  Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="AjaxWebService.Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>AJAX Web Form</title>
    <script type="text/javascript">

    function CallNextDate() 
    {
        AjaxWebService.Service.getNextBackupDate(1, OnSucceeded);
    }

    function CallHelloWorld() 
    {
        AjaxWebService.Service.HelloWorld(OnSucceeded);
    }
   function CallBookTitle() 
    {
        AjaxWebService.Service.GetBookTitle(OnSuccess, OnFail, "XmlDocument");
    }
    // This is the callback function that processes the Web Service return value in JSON format.
    function OnSucceeded(result)
    {
        var myresult = document.getElementById("Text1");
        myresult.value = result;
    }
   // This is the callback function that processes the Web Service return value in XML format.
    function OnSuccess(result)
    {
        var myresult = document.getElementById("Text1");
        myresult.value = "Title: " + result.documentElement.text;
    }
   // This is the callback function that processes the Web Service return value in XML format.
    function OnFail(error)
    {
        var myresult = document.getElementById("Text1");
        myresult.value = "Service Error: " + error.get_message();
    }
     </script>
  
    <style type="text/css">
        #Text1
        {
            width: 375px;
        }
        #Button2
        {
            width: 140px;
        }
    </style>
  
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Services>
        <asp:ServiceReference Path="~/Service.asmx"/>
        </Services>
        </asp:ScriptManager>
        <br />
        Result:&nbsp;&nbsp;         <input id="Text1" type="text" /><br />
        <br />
        <input id="Button1" type="button" value="Get Server Time" onclick="CallNextDate()" />&nbsp;&nbsp;
        <input id="Button2" type="button" value="Say Hello World" onclick="CallHelloWorld()" />&nbsp;&nbsp;
        <input id="Button3" type="button" value="Get Book Title" onclick="CallBookTitle()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <br />
        <br />
        <br />
        </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Balamurali Balaji
Founder BB Systems CIT-GPNP
India India
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170113.4 | Last Updated 18 Mar 2008
Article Copyright 2008 by Balamurali Balaji
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid