I have a registration form which is working perfectly well, I need to enhance it slightly from where it is. As it is users are able to register for an account wether the email has been previously used/allocated in the user db.
A client side call to the IsEmailAvailable function works great, just not working correctly server side. Here is the code.
<System.Web.Services.WebMethod()> _ Public Shared Function IsEmailAvailable(ByVal email As String) As Boolean Dim emailAddress As String = Membership.GetUserNameByEmail(email) Return (emailAddress Is Nothing) End Function
And my if statement:
If IsEmailAvailable(False) Then modalPopupEmail.Show() e.Cancel = True Else End If
So my question is, how can I pass the end value of the IsEmailAvailable function to my if statement correctly.
The method IsEmailAvailable takes a string as a input parameter. And when you are calling it, you are calling it wrong.
It should be something like this.
If not IsEmailAvailable(EmailAddress) Then modalPopupEmail.Show() e.Cancel = True Else End If
You have to pass the EmailAddress to this method when calling it.
You need to check with IsNullor empty method belongs to string class.
String.IsNullOrEmpty(emailAddress); would work great
Thanks for your reply.
One problem with your suggestion is that when I try to use emailAddress outside of the function, I get an "'emailAddress' is not declared."
I have tried both
If String.IsNullOrEmpty(emailAddress) Then
If IsEmailAvailable(emailAddress) Then
The if statement is located in
Protected Sub CreateUserWizard_CreatingUser(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) Handles CreateUserWizard1.CreatingUser
Thanks, appreciate your assistance here.
You are not invoking the method correctly.
If IsEmailAvailable(--------) Then modalPopupEmail.Show() e.Cancel = True Else End If
fill those dotted lines with the email you want to search. Maybe the email the user entered in the form.