Showing posts with label createuserwizard. Show all posts
Showing posts with label createuserwizard. Show all posts

Monday, March 26, 2012

newbie: Problem with CustomValidator

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?

JeffHi 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

"Jeff" wrote:

Quote:

Originally Posted by

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
>
>
>


Thank you!

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

"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.plwrote in message
news:504C4D4E-323A-460A-90AE-1A4CDEAD8237@.microsoft.com...

Quote:

Originally Posted by

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
>
"Jeff" wrote:
>

Quote:

Originally Posted by

>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
>>
>>
>>

newbie: Problem with CreateUserWizard

Hey

Below is the source code of the CreateUserWizard placed on one my web pages
(asp.net 2.0).

The problem is that the AssignUserToRole method isn't triggered when
clicking on the finish button (that Images/Go.gif image).

So I'm wondering what I'm doing wrong here

******************* markup ********************
<asp:CreateUserWizard FinishDestinationPageUrl="~/Default.aspx"
ID="CreateUserWizard1"
Width="300px" runat="server"
LoginCreatedUser="false"
CreateUserButtonType="Image"
CreateUserButtonImageUrl="Images/Go.gif"
OnFinishButtonClick="AssignUserToRole">

<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<label for="Username">User name:</label>
<asp:TextBox id="Username" runat="server" />

<label for="Password">Password:</label>
<asp:TextBox id="Password" runat="server"
TextMode="Password" />

<label for="ConfirmPassword">Confirm
Password:</label>
<asp:TextBox id="ConfirmPassword" runat="server"
TextMode="Password" />

<label for="Email">Email</label>
<asp:TextBox id="Email" runat="server" />

<label for="Question">Security question:</label>
<asp:TextBox id="Question" runat="server" />

<label for="Answer">Security answer:</label>
<asp:TextBox id="Answer" runat="server" />

</ContentTemplate>
</asp:CreateUserWizardStep>

<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
<ContentTemplate>rrrr</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>

***************** AssignUserToRole code **********************
protected void AssignUserToRole(object sender, EventArgs e)
{
MembershipUser user = Membership.GetUser();
user.IsApproved = false;
MailMessage mail = new MailMessage("name@dotnet.itags.org.somewhere.domain", user.Email,
"Thank you", "Hello World");
SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(mail);
mail.Dispose();
}

Any suggestions?I put the functionality into the CreatedUser event

Jeff

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:e7LUO45SHHA.920@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Hey
>
Below is the source code of the CreateUserWizard placed on one my web
pages (asp.net 2.0).
>
The problem is that the AssignUserToRole method isn't triggered when
clicking on the finish button (that Images/Go.gif image).
>
So I'm wondering what I'm doing wrong here
>
******************* markup ********************
<asp:CreateUserWizard FinishDestinationPageUrl="~/Default.aspx"
ID="CreateUserWizard1"
Width="300px" runat="server"
LoginCreatedUser="false"
CreateUserButtonType="Image"
CreateUserButtonImageUrl="Images/Go.gif"
OnFinishButtonClick="AssignUserToRole">
>
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
<label for="Username">User name:</label>
<asp:TextBox id="Username" runat="server" />
>
<label for="Password">Password:</label>
<asp:TextBox id="Password" runat="server"
TextMode="Password" />
>
<label for="ConfirmPassword">Confirm
Password:</label>
<asp:TextBox id="ConfirmPassword"
runat="server" TextMode="Password" />
>
<label for="Email">Email</label>
<asp:TextBox id="Email" runat="server" />
>
<label for="Question">Security
question:</label>
<asp:TextBox id="Question" runat="server" />
>
<label for="Answer">Security answer:</label>
<asp:TextBox id="Answer" runat="server" />
>
>
</ContentTemplate>
</asp:CreateUserWizardStep>
>
<asp:CompleteWizardStep ID="CompleteWizardStep1"
runat="server">
<ContentTemplate>rrrr</ContentTemplate>
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
>
***************** AssignUserToRole code **********************
protected void AssignUserToRole(object sender, EventArgs e)
{
MembershipUser user = Membership.GetUser();
user.IsApproved = false;
MailMessage mail = new MailMessage("name@.somewhere.domain", user.Email,
"Thank you", "Hello World");
SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(mail);
mail.Dispose();
}
>
Any suggestions?
>
>

newbie: Problem with CustomValidator

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?
JeffHi 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 ValidateEmptyTex
t
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
"Jeff" wrote:

> 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 ema
il
> is unique (see the code below).. The problem is that this UniqueEmail meth
od
> 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
>
>
Thank you!
I've just manage to solve it. The markup of the CustomValidator was missing:
ValidationGroup="CreateUserWizard1"
Jeff
"Milosz Skalecki [MCAD]" <mily242@.DONTLIKESPAMwp.pl> wrote in message
news:504C4D4E-323A-460A-90AE-1A4CDEAD8237@.microsoft.com...
> 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
> "Jeff" wrote:
>