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

April 13th, 2011, 03:36 PM
|
|
Authorized User
|
|
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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.
|
|

April 13th, 2011, 03:39 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

April 13th, 2011, 05:26 PM
|
|
Authorized User
|
|
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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...
|
|

April 14th, 2011, 03:46 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

April 14th, 2011, 06:41 AM
|
|
Authorized User
|
|
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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?
|
|

April 14th, 2011, 06:52 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

April 14th, 2011, 07:10 AM
|
|
Authorized User
|
|
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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...
|
|

April 14th, 2011, 07:25 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

April 14th, 2011, 09:07 AM
|
|
Authorized User
|
|
Join Date: Jan 2011
Posts: 89
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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.
|
|

April 14th, 2011, 09:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |