cmleung2
asked on
asp.net 2 check unique email for login user - double points if answer within 2 days
Hi,
I am going to give double points (total of 1000) if I can get the answer quickly. I really need this done, very urgent.
My website using asp.net 2, allow user to login and update their email. But whenever they do that, if they enter an email already exist for another user, a custom validation occur. I currently have the code for checking unique email when creating new user using the following:
Dim userCollection As MembershipUserCollection = Membership.FindUsersByEmai l(txtboxEm ail.Text)
If Page.IsValid Then
args.IsValid = True
If userCollection.Count > 0 Then
args.IsValid = False
End If
End If
But this causes the problem when the user press update without changing the email (since the email already exist for the current user).
I tried to check if the user name from the "FindUserByEmail" is the same with the current user, but couldn't figure out how to do that!
I tried to use an the "MembershipUserCollection. Copyto" to an array, and also tried to use a for loop to loop through each user and add it into the array, but both of them gives me the current user all the time even when I enter an email for another user)
My "testing" code so far to attempt this check is as follow:
Protected Sub CheckUniqueEmail(ByVal source As Object, ByVal args As System.Web.UI.WebControls. ServerVali dateEventA rgs)
Dim userCollection As MembershipUserCollection = Membership.FindUsersByEmai l(txtboxEm ail.Text)
Dim arruser As ArrayList = New ArrayList()
Dim member As MembershipUser
For Each member In userCollection
MsgBox(member.UserName)
arruser.Add(member.UserNam e)
Next
MsgBox(arruser.Item(0).ToS tring)
End Sub
Any help will be greatly appreciate. If you have any points request, give me an offer. As I said, I really need to get this over and done with, it's been more than 10 hours I am on this stupid thing. Thanks
Cecilia
I am going to give double points (total of 1000) if I can get the answer quickly. I really need this done, very urgent.
My website using asp.net 2, allow user to login and update their email. But whenever they do that, if they enter an email already exist for another user, a custom validation occur. I currently have the code for checking unique email when creating new user using the following:
Dim userCollection As MembershipUserCollection = Membership.FindUsersByEmai
If Page.IsValid Then
args.IsValid = True
If userCollection.Count > 0 Then
args.IsValid = False
End If
End If
But this causes the problem when the user press update without changing the email (since the email already exist for the current user).
I tried to check if the user name from the "FindUserByEmail" is the same with the current user, but couldn't figure out how to do that!
I tried to use an the "MembershipUserCollection.
My "testing" code so far to attempt this check is as follow:
Protected Sub CheckUniqueEmail(ByVal source As Object, ByVal args As System.Web.UI.WebControls.
Dim userCollection As MembershipUserCollection = Membership.FindUsersByEmai
Dim arruser As ArrayList = New ArrayList()
Dim member As MembershipUser
For Each member In userCollection
MsgBox(member.UserName)
arruser.Add(member.UserNam
Next
MsgBox(arruser.Item(0).ToS
End Sub
Any help will be greatly appreciate. If you have any points request, give me an offer. As I said, I really need to get this over and done with, it's been more than 10 hours I am on this stupid thing. Thanks
Cecilia
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you guys. TSmooth, your simple solution works perfectly. Thanks. Nautica, the viewstat works too, I actually took your idea to resolve one of my other problem. Thanks.
Cool! Thanks for the assist. :)
We also faced the problem like this.One only do the conditional validation like this below
CODE:
-------
If ( string.Compare(txtContactE
args.IsValid = NOT IsContactEmailExists(txtPr
End If