-
Feb 16th, 2011, 06:44 AM
#1
Thread Starter
Lively Member
[RESOLVED] Updating User Info with validation of unique email address.
Hi everyone
I have already done from register.aspx and works fine but I want to validate updated email to avoid any dulicated email.
can anyone help to do that?
bintaleb
-
Feb 16th, 2011, 07:46 AM
#2
Re: Updating User Info with validation of unique email address.
Hello,
Are you using the built in Membership Providers? I reason that I ask this question all the time, and advocate the use of them, is because what you are asking for (i.e. preventing duplicate emails) has already been thought about, and implemented within the provider model.
Gary
-
Feb 16th, 2011, 09:05 AM
#3
Thread Starter
Lively Member
Re: Updating User Info with validation of unique email address.
Hello Gary
thank you for quick response
Yes I have already used membership Providers in my project and I have prevented any new user to type duplicate email but let me clear my question.
regarding register.asp I have already done as mentioned, after that I create new page to allow user to change his email by using two textboxs control to confirm new email but I could not find method or property to validate if updated email is already exist or not, I can do that by using stored procedure but I don't because I believe there is a way to do that by membership provider but unfortunately I don't know.
note: in web.config I set RequiresUniqueEmail is true and works fine with me in createuserwizard.
bintaleb
-
Feb 16th, 2011, 08:31 PM
#4
Re: Updating User Info with validation of unique email address.
You could check with Membership.GetUserNameByEmail().
If the email the user enters does not return a current user then you are good to go.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Feb 17th, 2011, 02:28 AM
#5
Re: Updating User Info with validation of unique email address.
Ah, I see what you are getting at. Sorry for missing that!
As per the documentation, here:
http://msdn.microsoft.com/en-us/libr...iqueemail.aspx
RequiresUniqueEmail is only inspected at the time the new user is created. Afterwards, it will be up to you to ensure that each email address remains unique. As sap has mentioned, you could use that method, or there is also FindUsersByEmail:
http://msdn.microsoft.com/en-us/library/9c7by5c5.aspx
Gary
-
Feb 18th, 2011, 07:18 AM
#6
Thread Starter
Lively Member
Re: Updating User Info with validation of unique email address.
thanks sap and gary
now it is working good.
-
Feb 19th, 2011, 09:23 AM
#7
Re: [RESOLVED] Updating User Info with validation of unique email address.
Hello,
For the benefit of the community, you might like to post the code that you have used.
Gary
-
Feb 19th, 2011, 09:39 AM
#8
Thread Starter
Lively Member
Re: [RESOLVED] Updating User Info with validation of unique email address.
Originally Posted by gep13
Hello,
For the benefit of the community, you might like to post the code that you have used.
Gary
Hello Gary
here is what I have used to check a new email is already exist or not.
Code:
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
Dim CheckUserUser As String = Membership.GetUserNameByEmail(txtEmail.Text.Trim)
IF CheckUserUser <> Nothing Then
lblErrormsg.text = "Email is alraedy exist."
Else
Dim myObject As MembershipUser = Membership.GetUser()
myObject.Email = txtEmail.Text.Trim
Membership.UpdateUser(myObject)
lblErrormsg.text = "your Email has been updated successfully."
End If
but I am thinking to use custom validator to dispaly error message, is that possible?
-
Feb 19th, 2011, 09:44 AM
#9
Re: [RESOLVED] Updating User Info with validation of unique email address.
Hello,
You could use a custom validator, yes. You wouldn't easily be able to add client side validation, not unless you wanted to go to the length of creating a WebMethod that you could call from the client side. Not impossible, but a bit of work. Might be easier just to stick with what you have.
Gary
-
Feb 19th, 2011, 09:54 AM
#10
Thread Starter
Lively Member
Re: [RESOLVED] Updating User Info with validation of unique email address.
-
Feb 19th, 2011, 11:18 AM
#11
Re: [RESOLVED] Updating User Info with validation of unique email address.
Originally Posted by bintaleb
thank you so much.
Not a problem at all, happy to help where I can.
-
Feb 19th, 2011, 01:33 PM
#12
Re: [RESOLVED] Updating User Info with validation of unique email address.
You could(should) also add a validation of a correct email formatting on the client side.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Feb 20th, 2011, 04:58 AM
#13
Re: [RESOLVED] Updating User Info with validation of unique email address.
Originally Posted by sapator
You could(should) also add a validation of a correct email formatting on the client side.
Agreed, you could add a client side validation to check the validity of the format of the email address with the use of a Regular Expression, but that obviously wouldn't tell you whether that email address was already in use or not.
Gary
-
Feb 23rd, 2011, 02:21 AM
#14
Re: [RESOLVED] Updating User Info with validation of unique email address.
Hello there,
The following webpage just came through on my RSS stream, and I immediately thought of this thread:
http://www.4guysfromrolla.com/articles/022311-1.aspx
Hope it helps!
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|