Link to home
Start Free TrialLog in
Avatar of cmleung2
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.FindUsersByEmail(txtboxEmail.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.ServerValidateEventArgs)
        Dim userCollection As MembershipUserCollection = Membership.FindUsersByEmail(txtboxEmail.Text)
        Dim arruser As ArrayList = New ArrayList()
        Dim member As MembershipUser
        For Each member In userCollection
            MsgBox(member.UserName)
            arruser.Add(member.UserName)
        Next
        MsgBox(arruser.Item(0).ToString)
     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
Avatar of NauticalNonsense
NauticalNonsense
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
 We also faced the problem like this.One only do the conditional validation like this below

CODE:
-------

If ( string.Compare(txtContactEmail.Text.Trim(), User.Identity.Name,true) != 0)
          args.IsValid = NOT IsContactEmailExists(txtPrimaryContactEmail.Text.Trim())
End If
 
Avatar of cmleung2
cmleung2

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. :)