I’ve read several posts about this issue (here and in other sites) but no one is working for me. I’m trying to check if a given email is already registered in a database during the register process.
I’ve a page called Register.aspx in which I’ve declared the follow JavaScript function:
function check_email_availability(src, args) {
$.ajax({
type: "POST",
async: false,
timeout: 500,
contentType: "application/json",
url: "Register.aspx/CheckEmailAvailability",
data: "{ 'email' : '" + args.Value + "' }",
success: function (result) {
args.IsValid = result.d;
}
});
}
In the other hand, in the code behind in Register.aspx.vb, I’ve the follow WebMethod:
<System.Web.Services.WebMethod()> _
Public Shared Functiion CheckEmailAvailability(ByVal email As String) As String
If Membership.GetUser(email) Is Nothing Then
Return "True"
Else
Return "False"
End Function
I’m trying to launch the JavaScript function through a CustomValidator but I receive from Chrome’s Console the follow message:
Uncaught TypeError: Cannot read property 'Value' of undefined
The error appears right in the line
data: "{ 'email' : '" + args.Value + "' }",
so -always using Chrome-, I’ve set a breakpoint on that line and, from Console, I’ve write
args.Value
and I’ve obtained the correct value, i.e., the email address that I had entered. So… I’m a little lost.
I appreciate any help.
Well, I finally made it work. I share here the used code. To get into context, in the user registration process, I want to check the email availability.
In the head of
Register.aspx:In the body of
Register.aspx:In the codebehind (
Register.aspx.vb):I hope this will be useful to someone. There is a question almost identical using C# that have help me to make it work.
Regards,