Place script manager in a webpage and
Here we need to enable "EnablePageMethods" Property of ScripManager.
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
</asp:ScriptManager>
Then we need to attach event to the particular return value function
Default.aspx:
==========
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchUser.aspx.cs" Inherits="Wizard.SearchUser" %>
<!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></title>
<script type="text/javascript" language="javascript">
{
var emailAddressErrMsg = document.getElementById("emailAddressErrMsg");
var btnNextAdd = document.getElementById('<%=btnNext.ClientID %>');
var emailAddressExist = ResultString;
if (emailAddressExist == 1)
{
emailAddressErrMsg.innerHTML = "Entered email address Already exist.";
emailAddressErrMsg.style.display = 'inline';
btnNextAdd.disabled = true;
}
else
{
emailAddressErrMsg.style.display = 'none';
btnNextAdd.disabled = false;
}
}
function CheckEmailAddress(src)
{
PageMethods.ValidateEmailAddress(src.value, ValidateEmailAddress_Result);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" >
</asp:ScriptManager>
<div>
<div class="errMessage" id="emailAddressErrMsg" style="display:none;">
*Please enter a Email Address.
</div>
<asp:Button ID="btnNext" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
Default.aspx.cs:
===========
[System.Web.Services.WebMethod]
public static int ValidateEmailAddress(string emailAddress)
{
try
{
int emailAddresscount = CheckEmailAddressExist(emailAddress);
if (emailAddresscount > 0)
{
return 1;
}
else
{
return 0;
}
}
catch { return 0; }
}
No comments:
Post a Comment