Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 14th, 2011, 04:17 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
I am using the following jquery in head section:
Sure, but how does that end up in the final HTML?


Quote:
How this behavior can be conquered?
It's usually better to start a new thread for a new topic, making it easier for everybody to find the stuff you're looking for. Also, since this is getting quite off-topic from the book Beginning ASP.NET 4, it's also probably better to find a more general ASP.NET category for these kind of questions: http://p2p.wrox.com/asp-net-4-539/

That said, the control in the IDE doesn't know about that setting yet (only at run-time). So when you convert it to a template, you get all available code. I think you can just remove it from the control and it should work.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 17th, 2011, 01:16 PM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Quote:
It's usually better to start a new thread for a new topic
Sorry, if it bothers you.

Quote:
I think you can just remove it from the control and it should work.
Yeah , it should work but isn't there any proper solution?
Thanks
 
Old November 18th, 2011, 09:50 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Sorry, if it bothers you.
It doesn't bother me that much but by posting in separate threads you make it easier for future visitors to find stuff they are looking for....

Quote:
Yeah , it should work but isn't there any proper solution?
Not sure, but I don't think so. Once you rip apart the control it loses some of its internal implementation. You could hide the relevant controls programamtically based on the current configuration settings for Membership. However, if you don't need to switch back, deleting the controls is way easier.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old November 18th, 2011, 10:23 AM
Friend of Wrox
Points: 1,469, Level: 15
Points: 1,469, Level: 15 Points: 1,469, Level: 15 Points: 1,469, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2009
Posts: 341
Thanks: 14
Thanked 3 Times in 3 Posts
Smile

Quote:
by posting in separate threads you make it easier for future visitors to find stuff they are looking for....
I do agree with you. I'll take care next time.

Quote:
You could hide the relevant controls programamtically based on the current configuration settings for Membership
Can you please give a short example.
Thanks...
 
Old November 18th, 2011, 10:26 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Something like this may work (untested):

1. Wrap the relevant table rows you want to hide in a PlaceHolder called HideMe (or whatever)

2. Add the following code to Page_Load:

Code:
 
CreateUserWizard1.CreateUserStep.FindControl("CreateUserStepContainer").FindControl("HideMe").Visible = Membership.Provider.RequiresQuestionAndAnswer;
Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 20th, 2012, 05:51 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Email format validation in CreateUser Wizard

I'm having a problem with validating an email address for proper form (not if it is an actual live email address). In the case of a mis-typed email address, the following code works fine and I suppose I can live with this. However, it is a work-around to avoid a problem. The work-around is the use of the "alert" in the jquery script. As long as I include this alert the code works OK. If I remove the alert then the code does not work correctly after the user reenters a properly formed email address - the user has to click the "create user" button twice for actual create user process to fire. The first click takes focus off on the email text box and allows the validation process to run. If the validation process determines that the email is now correctly formatted, the process just sits there and the user has no clue what is happening. If they decide to click the button again, then the create user process is fired and all is well. However, this is no way to run the show! The reason the alert works is not clear to me - has something to do with moving the focus. Also, the "focus" code in the jquery does not seem to work.

I've tried all kinds of variations for this problem and posted on the Microsoft ASP forum and so far no one has a clue how to fix this. It seems that I should just be able to put the regular expression in the properties option for email validation and that should be it. However, that produces the same problem. Trying to trap the create user button is difficult because of the internal timing of the CreateUserWizard - I tried lots of variations of this approach.

The following code is pretty simple but it seems that I'm not understanding some fundamental thing about how to validate an email and still have the normal flow. The normal flow should be:

1. User enters bad email format, clicks Create User and then gets an error message in the usual place
2. User enters a good email, clicks Create User and the create user process proceeds normally

BTW, this does not seem to be a problem if I leave in the security questions. But, I don't want the security question.



<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPages/1Column.master" AutoEventWireup="false" CodeFile="SignUpTest.aspx.vb" Inherits="SignUpTest" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/jscript" src="../scripts/jquery-1.7.2.min.js">
</script>
<script type="text/jscript">

$(function ()
{
$("#ContentPlaceHolder1_CreateUserWizard1_CreateUs erStepContainer_Email").bind('change', function (event)
{
if (/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test($(this).val()))
{
$("#ContentPlaceHolder1_CreateUserWizard1___Custom Nav0_StepNextButton").trigger('click')
}
else
{
alert("Please use a valid email")
$("#ContentPlaceHolder1_EmailErrMsg").text("Plea se enter a valid email address")
$("#ContentPlaceHolder1_CreateUserWizard1_CreateUs erStepContainer_Email").trigger('focus')
};
});
});
</script>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" >
<ErrorMessageStyle BackColor="#FFFFCC" BorderColor="Black"
BorderStyle="Solid" />
<ValidatorTextStyle BackColor="#FFFFCC" />
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<CustomNavigationTemplate>
<table border="0" cellspacing="5" style="width:100%;height:100%;">
<tr align="right">
<td align="right" colspan="0">
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext"
Text="Create User" ValidationGroup="CreateUserWizard1"/>
</td>
</tr>
</table>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
<asp:Label ID="EmailErrMsg" runat="server" Text=" " ForeColor="Red"></asp:Label>
</asp:Content>

There is no code-behind. Thanks for any insight on this problem.
 
Old April 21st, 2012, 03:24 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Why are you going this route? Why not use a RegularExpressionValidator as explained in the book? Or was that what you meant with " It seems that I should just be able to put the regular expression in the properties option for email validation and that should be it"?

Haven't really tested the code, but it looks like it can be problematic. Triggering your own focus and clicks doesn't make that much sense to me. Do you really need this? I think there are much easier solutions....


Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 21st, 2012, 04:35 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Looking for that easier solution

Quote:
Originally Posted by Imar View Post
doesn't make that much sense to me.I think there are much easier solutions....
Imar
Hi Imar,

I agree that what I've done does not make sense and I'm trying to figure out how to stop doing this!

The CreateUser Wizard has several properties related to email:

EmailRegularExpression, EmailRegularExpressionErrorMessage, & EmailRequiredErrorMessage

I thought it would be a simple matter to plug in a regular expression (as suggested on the MS ASP Forum) and then an incorrectly formed email address would be caught, the error message displayed, and then proceed normally once the user corrected the email address. All of this works fine except that after the email address is corrected and the user clicks "create user" nothing happens unless the user clicks "create user" a second time. And recall that I don't have the security question text boxes.

In your book, starting on page 592 you cover the CreateUserWizard but I didn't see anything there about using a regular expression for validating the email address. On page 306 you have an example of using a RegularExpressionValidator for an email address that is not involved with the CreateUserWizard. Are you suggesting I could combine the asp:RegularExpressionValidator with the CreateUserWizard? However, this also seems to be a work-around for the EmailRegularExpression property that is part of the CreateUser Wizard.

The problem has never been the failure of the regular expression string failing to properly validate - it does that just fine. The problem is the flow of control as the user sees things. They would expect to correct the bad email and then click the create user button again and proceed onward. The CreateUser process does not do that - it just sits there until the user clicks the create user button again.

I keep wondering if there is some key point here that I'm just failing to recognize? Thanks for any insight.
 
Old April 21st, 2012, 11:25 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Simple Example

Hi Imar,

Here is a very simple example of the original problem:

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPages/1Column.master" AutoEventWireup="false"
CodeFile="SignUpTest2.aspx.vb" Inherits="SignUpTest2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<asp:CreateUserWizard ID="CreateUserWizard3" runat="server" ContinueDestinationPageUrl="~/Default.aspx"
EmailRegularExpression='\w+([-+.&apos;]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*'>
<MailDefinition BodyFileName="~/App_Data/SignUpConfirmation.txt" Subject="Your new account at xxxxx">
</MailDefinition>
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep3" runat="server">
</asp:CreateUserWizardStep>
<asp:CompleteWizardStep ID="CompleteWizardStep3" runat="server">
</asp:CompleteWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
</asp:Content>

The following assume you have setup the config file for membership and all that works with your database (as mine does)

Step 1:

Enter a name
Enter password and confirm password
Enter an incorrectly formatted email address: "xxx"
Click "Create User" button and get an error message for invalid email

Step 2:

Correct email with a properly formed address "someone@gmail.com"
Click "Create User" button - error message goes away and nothing else happens.

Step 3:

Click "Create User" button again and get "Complete - Your Account has been successfully created" (and you can see it in your membership database)

The problem is in step 2 - why does the create user process just stall until the user clicks the create user button a second time?
 
Old April 22nd, 2012, 04:50 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I can reproduce the problem with the steps you described. I think the reason for this is that the onblur for the e-mail address fires when you click the button; this causes validation to fire first which sees that the e-mail address is now filled in correctly. But somehow this causes the button to no longer submit the form. It works fine for me if I manually tab out of the field before I click the Create user button.

I see a simple, albeit it slightly hacky solution: when users hover over the Create User button, remove the focus from the e-mail field. This way, validation is triggered before you click the button. E.g.:

Code:
 
<asp:Button ID="StepNextButton" runat="server" CommandName="MoveNext" 
Text="Create User" 
onmouseover="document.getElementById('cpMainContent_CreateUserWizard3_CreateUserStepContainer_Email').blur();" 
ValidationGroup="CreateUserWizard3" />
You could also do this in Code Behind using the Attributes collection of the button.

In order to get at the button, you need to click Convert to CustomNavigationTemplate on the control's Smart Tasks panel.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!




Similar Threads
Thread Thread Starter Forum Replies Last Post
Provider error by CreateUser dbardelt BOOK: Silverlight 4 Problem - Design - Solution 4 June 6th, 2011 08:21 AM
UserInformationService.CreateUser p115 Gabor66 BOOK: Silverlight 4 Problem - Design - Solution 1 May 14th, 2010 03:50 AM
wizard control Bill Crawley ASP.NET 2.0 Professional 0 July 12th, 2007 09:55 AM
CreateUser Error Gadall ASP.NET 2.0 Professional 1 May 9th, 2007 01:15 AM
Saving personalization properties w/CreateUser k8277 ASP.NET 2.0 Basics 0 April 5th, 2007 01:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.