——————————————WebForm1.aspx——————————————

// This function calls the Web service method

// passing simple type parameters and the

// callback function

function CallWebMethod() {
// debugger;
var User_Name = document.getElementById(”).value;

checkDuplicateUserName.WebService1.CheckDuplicate(User_Name, OnSucceeded, OnError);

}

// This is the callback function invoked if the Web service

// succeeded

function OnSucceeded(result) {

var rsltElement = document.getElementById(“lblDuplicate”);
rsltElement.innerHTML = “”;
if (result.length>0)

for (var i = 0; i < result.length; i++)
{
rsltElement.innerHTML += result[i] + ‘
‘;
}
//rsltElement.innerHTML = “This User Name is exist”;

else

rsltElement.innerHTML = “”;
}

function OnError(error) {

// Display the error.

alert(“Service Error: ” + error.get_message());
}

——————————————WebService—————————————–

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Collections;

namespace checkDuplicateUserName
{
///
/// Summary description for WebService1
///
[WebService(Namespace = “http://tempuri.org/&#8221;)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]

public class WebService1 : System.Web.Services.WebService
{

[WebMethod]
[ScriptMethod(ResponseFormat= ResponseFormat.Json)]
public List CheckDuplicate(string username)
{
List userdetail = new List();
PL.UserProperties objuser = DAL.clUsers.LoadByUserName(username);
if (objuser != null)
{
userdetail.Add(objuser.Id.ToString());
userdetail.Add(objuser.FullName.ToString());
userdetail.Add(objuser.Email.ToString());
}
return userdetail;
}
}
}

Advertisements