WebService.asmx
----------------------------------
[WebMethod]
public string CheckUserNames(string Email)
{
IFileSystem objFileSystem = null;
string strResult = string.Empty;
try
{
objFileSystem = new FileSystemDAL();
strResult = objFileSystem.CheckUserName(Email);
}
catch (Exception ex)
{
throw ex;
}
return strResult;
}
Page.ascx
---------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CreateEditAccount_UC.ascx.cs" Inherits="FileSystem.UI.UserControls.CreateEditAccount_UC" %>
<%--this javascriptis used to show the message after valid statement.--%>
// jQuery.validator.setDefaults({
// debug: true,
// success: "valid",
// submitHandler: function () {
// alert("submitted!");
// var Email = $("#txtEmail").val();
// var dataString = 'Email=' + Email;
// alert(dataString);
// $.ajax({
// type: "GET",
// url: "InputAndOutput_WS.asmx/CheckUserName",
// data: dataString,
// // contentType: "application/json; charset=utf-8",
// // dataType: "json",
// success: OnSuccess,
// failure: function (response) {
// alert(response);
// }
// });
// alert("Ashutosh: " + dataString);
// }
// });
function ShowAvailability() {
var Email = $("#txtEmail").val();
var dataString = 'Email=' + Email;
$.ajax({
type: "POST",
url: "InputAndOutput_WS.asmx/CheckUserNames",
data: $.stringify(dataString),
contentType: "application/xml; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response);
}
});
}
function OnSuccess(response) {
var mesg = $("#mesg")[0];
alert(response);
switch (response.d) {
case "true":
mesg.style.color = "green";
mesg.innerHTML = "Available";
break;
case "false":
mesg.style.color = "red";
mesg.innerHTML = "Not Available";
break;
case "error":
mesg.style.color = "red";
mesg.innerHTML = "Error occured";
break;
}
}
function OnChange(txt) {
$("#mesg")[0].innerHTML = "";
}
<%--write the following javascript for passing the parameter for jquery--%>
$(document).ready(function() {
$("#FileSystemform").validate({
rules: {
<%=txtFirstName.UniqueID %>: {minlength: 5,required: true},
<%=txtLastName.UniqueID %>: {minlength: 5,required: true},
<%=txtEmail.UniqueID %>: {required: true},
<%=txtPassword.UniqueID %>: {minlength: 5,required: true},
<%=txtRetypePassword.UniqueID %>: {minlength: 5,equalTo: "#txtPassword",required: true}
},
messages: {
<%=txtFirstName.UniqueID %>:{required: "Plaese enter your first name.",minlength: "First name must be atleaet of 5 characters."},
<%=txtLastName.UniqueID %>:{required: "Plaese enter your last name.", minlength: "Last name must be atleaet of 5 characters."},
<%=txtEmail.UniqueID %>:{ required: "Plaese enter your valid Email Id."},
<%=txtPassword.UniqueID %>:{ required: "Plaese enter Password."}
}
});
});
Create Account | |
First Name | |
Last Name | |
Email | |
Password | |
Renter | Width="242px"> |
Width="108px" /> | |
I am calling the Jquery function ShowAvailability() on txtPassword OnClick event.
Please help me to show value undifined to either true or false.
Iftikar HussainPosted Jun 26, 2013, 4:32 AM
Please modify your JQuery method ShowAvailability() as shown below
function ShowAvailability() {
and in your WebService include Script block
[WebService(Namespace = "http://tempuri.org/")]
Please let me know if you need more information
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
Venkatesh KumarPosted Jun 25, 2013, 10:35 AM