newbie: Problem with CustomValidator

J

Jeff

Hey

asp.net 2.0

I'm creating a web site where people must register to get access to
restricted area. In the CreateUserWizard control I've added a check on email
is unique (see the code below).. The problem is that this UniqueEmail method
isn't triggered when leaving the Email field or submitting the
CreateUserWizard (click on the finish button)

<asp:CustomValidator ID="valUniqueEmail" runat="server" ErrorMessage="Your
Email address is already taken" ControlToValidate="Email"
OnServerValidate="UniqueEmail"></asp:CustomValidator>

protected void UniqueEmail(object source, ServerValidateEventArgs args)
{
MembershipUserCollection allUsers = Membership.GetAllUsers();
Debug.WriteLine("UniqueEmail");
foreach (MembershipUser user in allUsers)
{
if (user.Email == args.Value)
{
Debug.WriteLine("Testing " + user.UserName + " against " +
args.Value);
args.IsValid = false;
}
}
}

Any suggestions?

Jeff
 
G

Guest

Hi Jeff,

Few things:

1. If EnableClientValidation is set to false, when you leav the control,
validation is not preformed (value is only validated when page is posted
back). In addition to that, CustomValidator control exposes ValidateEmptyText
property, which should be set to true if you expect empty text is considered
as a valid value for validation.

2. Because you're utilizing event wire up, make sure AutoEventWireup is set
to true in <@Page > directive

3. Any chances submit button has CausesValidation property set to false?

Hope it helps

Milosz
 
J

Jeff

Thank you!

I've just manage to solve it. The markup of the CustomValidator was missing:
ValidationGroup="CreateUserWizard1"
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top