Wednesday, May 8, 2013

sample code for call webservice using ajax in

Here we call webservice using ajax update panal and javascript .
We see also how an ASP.NET AJAX-enabled web service generates the JavaScript needed to call the web service.
: sample code as below:
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
public class WebService : System.Web.Services.WebService {
    public WebService () {
        //Uncomment the following line if using designed components
    public string SayHello(int a,int b)
        return Convert.ToString(a + b);
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
function Button1_onclick() {
ret = WebService.SayHello(document.getElementById('Text1').value,document.getElementById('Text2').value,  OnComplete, OnTimeOut, OnError);
function OnComplete(arg) {
function OnTimeOut(arg) {
alert("TimeOut encountered when calling Say Hello.");
function OnError(arg) {
alert("Error encountered when calling Say Hello.");
// -->
      <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <asp:ServiceReference Path="~/WebService.asmx" />
        <br />
            <input id="Text1" type="text" /><br />
                       <input id="Text2" type="text" /><br />
            <input id="Button1" style="width: 158px" type="button" value="button" language="javascript" onclick="return Button1_onclick()" />&nbsp;</div>

Source code download : Source code

If you are searching life partner. your searching end with now offer free matrimonial website which offer free message, free chat, free view contact information. so register here : Free matrimonial website