Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old April 13th, 2011, 03:36 PM
Authorized User
Points: 445, Level: 7
Points: 445, Level: 7 Points: 445, Level: 7 Points: 445, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Have enclosed the code now, I just created a new website and chose ASP.NET website that has membership pages etc already there and I modified the SqlDataSource in the CreateUserWizard on Register.aspx to include other user info to store in a separate table linked with the UserID.

I just want to grab the day/month/year from drop down lists, and pass that into DateOfBirth InsertParameter of the SqlDataSource as DateTime to store in the database.
Reply With Quote
  #12 (permalink)  
Old April 13th, 2011, 03:39 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I just created a new website and chose ASP.NET website that has membership pages etc already there
Any idea how you got that template? Like I said, it's not part of standard Visual Studio templates.

Anyway, can't you do the same as with the UserId:

DataSource.InsertParameters.Add("Dob", DateTime.Now)

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!
Reply With Quote
  #13 (permalink)  
Old April 13th, 2011, 05:26 PM
Authorized User
Points: 445, Level: 7
Points: 445, Level: 7 Points: 445, Level: 7 Points: 445, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Ok, this works if I hard code DateTime.Now(), so I collected the data from the drop down lists, passed them to a dateTime variable added in the InsertParameters:

Dim day As DropDownList = CreateUserWizardStep1.ContentTemplateContainer.Fin dControl("ddlDay")
Dim month As DropDownList = CreateUserWizardStep1.ContentTemplateContainer.Fin dControl("ddlMonth")
Dim year As DropDownList = CreateUserWizardStep1.ContentTemplateContainer.Fin dControl("ddlYear")
Dim DoB As DateTime = New DateTime(CInt(year.SelectedValue), CInt(month.SelectedValue), CInt(day.SelectedValue))

DataSource.InsertParameters.Add("DateOfBirth", DoB)

But when creating the user I get the following error:
Input string was not in a correct format.

I dont understand because I'm using the 3rd overload of DateTime which accepts year, month, day as integers...
Reply With Quote
  #14 (permalink)  
Old April 14th, 2011, 03:46 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
>> I just created a new website and chose ASP.NET website that has membership pages etc already there

Any idea how you got that template? Like I said, it's not part of standard Visual Studio templates.
Can we get this out of the way first so I don't have to repeat the question on each post I am making? Curious to see how you got this template and code. ;-)

Quote:
Input string was not in a correct format.
I dont understand because I'm using the 3rd overload of DateTime which accepts year, month, day as integers...
Hard to tell without seeing the code that creates the drop dows and the data they contain. Looks like the date can't be created. What do the SelectedValue properties contain?

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!
Reply With Quote
  #15 (permalink)  
Old April 14th, 2011, 06:41 AM
Authorized User
Points: 445, Level: 7
Points: 445, Level: 7 Points: 445, Level: 7 Points: 445, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I extended the CreateUserWizard thats on Register.aspx when you start a web site project (not the 'empty web site') in VWD 2010 Express. Because I wanted to store more user details I created a UserDetails table in aspnetdb using UserGUID as the key. I decided against profiles because I believe I'll need to access user details in the database.

By the way I finished your book a few days ago and learned a lot, very helpful stuff in there which I'm sure I'll be referencing for a long time.

Using a break point I found that it was trying to set "Jan" to the integer value of the month so I fixed this with a select case statement and now is accepted.

I'm still getting an issue though where if I dont fill in all details it still tries to insert the user returning an error saying it cant fill null values into FirstName etc. I dont understand this because I set RequiredFieldValidators on all required fields in the DB??

I also tried adding Page.IsValid:
If Page.IsValid Then
DataSource.Insert()
End If

Could this be because I extended the existing CreateUserWizard and havent properly handled the required fields?
Reply With Quote
  #16 (permalink)  
Old April 14th, 2011, 06:52 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I extended the CreateUserWizard thats on Register.aspx when you start a web site project (not the 'empty web site') in VWD 2010 Express
But where then did the SqlDataSource come from? When I create a new web site I get a Register.aspx page, but it does not contain a SqlDataSource nor any SQL specific code.

Quote:
Using a break point I found that it was trying to set "Jan" to the integer value of the month so I fixed this with a select case statement and now is accepted.
Or you could have used Integer values as the Value of the option elements, while displaying the month name to the user.

Quote:
By the way I finished your book a few days ago and learned a lot, very helpful stuff in there which I'm sure I'll be referencing for a long time.
That's good to hear!

Quote:
Could this be because I extended the existing CreateUserWizard and havent properly handled the required fields?
Don't know. Don't they fire at the client? Do the standard validators work OK?

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!
Reply With Quote
  #17 (permalink)  
Old April 14th, 2011, 07:10 AM
Authorized User
Points: 445, Level: 7
Points: 445, Level: 7 Points: 445, Level: 7 Points: 445, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I added the sql data source to handle the extra data. The validators for username and password work but if I leave out anything else like security question, email, first name etc. I just get the YSOD telling me it's trying to add nulls.


<asp:TextBox ID="FirstName" runat="server" Width="200px"></asp:TextBox>
<asp:RequiredFieldValidator ID="FirstNameRequired" runat="server" ControlToValidate="FirstName" ErrorMessage="First Name is required." ToolTip="First Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

I see that the field validator has ValidationGroup="CreateUserWizard1, would this be a collection I need to add the validation control to? I cant see i anywhere in the code or code-behind...
Reply With Quote
  #18 (permalink)  
Old April 14th, 2011, 07:25 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
I added the sql data source to handle the extra data.
Ah, there we have it. I asked about that control a number of times and you said:
Quote:
There is a SqlDataSource that is inside the ContentTemplate element of the CreateUserWizard, I can see that the RegisterUser_CreatedUser event is being handled and programatically referencing the data source and inserting:
which seemd to imply the control was "just there" and that you didn't add it.

Quote:
would this be a collection I need to add the validation control to?
No. All controls with the same ValidationGroup are validated at the same time. You could try passing the name of the group in the Validate method. It's a bit hard for me to recommend more as I can't easily run your page in my own site.

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!
Reply With Quote
  #19 (permalink)  
Old April 14th, 2011, 09:07 AM
Authorized User
Points: 445, Level: 7
Points: 445, Level: 7 Points: 445, Level: 7 Points: 445, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Apologies I thought the data source was already there but after checking a new project it's not so I must have added it.

I added the validate method to the RegisterUser.CreatedUser event:

Validate("CreateUserWizard1")

If Page.IsValid Then
DataSource.Insert()
End If

This allows the user to be created without any other than username & password. It seems that the RequiredFieldValidator's on all other controls simply arent being run.
Reply With Quote
  #20 (permalink)  
Old April 14th, 2011, 09:41 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Could it be that none of your validators fire? E.g. all those with the group set to CreateUserWizard1? I think the Create User button has its own group set, so none of the controls are validated. Try replacing this:

Code:
 
</ContentTemplate>
</asp:CreateUserWizardStep>
with this:

Code:
 
</ContentTemplate>
 <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>
This assigns the Create User button the same ValidationGroup.

Hope this hekps,

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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code for date of Birth.... aaronabdiel Visual Studio 2005 1 January 2nd, 2008 03:25 AM
Birth Date listings xp_mahesh JSP Basics 0 June 2nd, 2006 12:57 AM
Validation for Date of Birth crmpicco Javascript How-To 2 June 30th, 2005 08:13 AM
Date of birth question satts Access 10 February 24th, 2005 11:21 AM
validating date of birth in asp shoakat Classic ASP Databases 7 September 3rd, 2004 12:18 AM



All times are GMT -4. The time now is 07:01 AM.


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