Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional 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 July 2nd, 2007, 03:59 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default CreateUserWizard and Profiles

I'm trying to create a profile for a user as they are being created. There's a great example out there by Scott Guthrie that does exactly what I want. My program runs with no errors, but the profile data is not being saved. I'm really not sure what the problem is, so am hoping someone here can give me a hand. Here is my code.

In the web.config I have the profile defined as such:
Code:
<profile defaultProvider="BSGProfileProvider">
            <providers>
                <add
                    name="BSGProfileProvider"
                    type="System.Web.Profile.SqlProfileProvider" 
                    connectionStringName="BSGNETDB" />
            </providers>
            <properties>
                <add
                    name="Customer"
                    type="string" />
                <add
                    name="ShipTo"
                    type="string" />
            </properties>
        </profile>


My aspx page looks as such:

Code:
<%@ Page Language="vb" Debug="true" %>

<script runat="server">
    Sub CreateUserWizard1_CreatedUser(ByVal sender as Object, ByVal e as EventArgs)
        Dim p as ProfileCommon = CType(ProfileCommon.Create(CreateUserWizard1.UserName, true), ProfileCommon)
        Dim CustNum as TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("CustomerNum"), TextBox)
        Dim ShipNum as TextBox = CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShipNum"), TextBox)

        p.Customer = CustNum.Text
        p.ShipTo = ShipNum.Text
        p.Save()
    End Sub

    Sub AssignUserToRoles_Activate(ByVal sender as Object, ByVal e as EventArgs)
    AvailableRoles.DataSource = Roles.GetAllRoles()
    AvailableRoles.DataBind()
    End Sub

    Sub AssignUserToRoles_Deactivate(ByVal sender as Object, ByVal e as EventArgs)
         Roles.AddUserToRole(CreateUserWizard1.UserName, AvailableRoles.SelectedValue)
    End Sub
</script>

<html>
<head>
    <title>Create User</title>
    <link rel="stylesheet" type="text/css" href="~/common/portal.css">
</head>
<body bgcolor="#000000" text="#FFFFFF" topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" rightmargin="0" leftmargin="0" bottommargin="0">
<form id="CreateUserForm" runat="server">
    <div align="center"><br><br><br><br>
        <asp:CreateUserWizard id="CreateUserWizard1" runat="server">
            <WizardSteps>
                <asp:CreateUserWizardStep id="CreateUserWizardStep1" runat="server">
                    <ContentTemplate>
                        <asp:Table id="CreateUser" runat="server"
                            Width="100%" CellPadding="0" CellSpacing="0" BackColor="#D7D7D7">
                            <asp:TableRow>
                                <asp:TableCell ColumnSpan="2" BackColor="#6B696B" Style="color: white;">
                                    Create UserID
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell Width="50%" HorizontalAlign="right" Style="color: black;">
                                    <asp:Label id="lblUserName" runat="server"
                                        Text="User Name: " AssociatedControlID="UserName" />&nbsp;&nbsp;
                                </asp:TableCell>
                                <asp:TableCell Width="50%">
                                    <asp:TextBox id="UserName" runat="server" />
                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
                                        ControlToValidate="UserName" ErrorMessage="User Name is required."
                                        ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell Width="50%" HorizontalAlign="right" Style="color: black;">
                                    <asp:Label id="lblEmail" runat="server"
                                        Text="E-mail Address: " AssociatedControlID="Email" />&nbsp;&nbsp;
                                </asp:TableCell>
                                <asp:TableCell Width="50%">
                                    <asp:TextBox id="Email" runat="server" />
                                    <asp:RequiredFieldValidator ID="EmailRequired" runat="server"
                                        ControlToValidate="Email" ErrorMessage="Email is required."
                                        ToolTip="Email is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell Width="50%" HorizontalAlign="right" Style="color: black;">
                                    <asp:Label id="lblPassword" runat="server"
                                        Text="Password: " AssociatedControlID="Password" />&nbsp;&nbsp;
                                </asp:TableCell>
                                <asp:TableCell Width="50%">
                                    <asp:TextBox id="Password" runat="server"
                                        TextMode="Password" />
                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
                                        ControlToValidate="Password" ErrorMessage="Password is required."
                                        ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell Width="50%" HorizontalAlign="right" Style="color: black;">
                                    <asp:Label id="lblConfirmPassword" runat="server"
                                        Text="Re-type Password: " AssociatedControlID="ConfirmPassword" />&nbsp;&nbsp;
                                </asp:TableCell>
                                <asp:TableCell Width="50%">
                                    <asp:TextBox id="ConfirmPassword" runat="server"
                                        TextMode="Password" />
                                    <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server"
                                        ControlToValidate="ConfirmPassword" ErrorMessage="Confirm Password is required."
                                        ToolTip="Confrim Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell ColumnSpan="2" BackColor="#6B696B" Style="color: white;">
                                    Enter Customer Info
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell Width="50%" HorizontalAlign="right" Style="color: black;">
                                    <asp:Label id="lblCustomerNum" runat="server"
                                        Text="Enter Customer #: " AssociatedControlID="CustomerNum" />&nbsp;&nbsp;
                                </asp:TableCell>
                                <asp:TableCell Width="50%">
                                    <asp:TextBox id="CustomerNum" runat="server" />
                                    <asp:RequiredFieldValidator ID="CustomerNumRequired" runat="server"
                                        ControlToValidate="CustomerNum" ErrorMessage="Customer # is required."
                                        ToolTip="Customer # is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell Width="50%" HorizontalAlign="right" Style="color: black;">
                                    <asp:Label id="lblShipToNum" runat="server"
                                        Text="Enter Ship To #: " AssociatedControlID="ShipToNum" />&nbsp;&nbsp;
                                </asp:TableCell>
                                <asp:TableCell Width="50%">
                                    <asp:TextBox id="ShipToNum" runat="server" />
                                    <asp:RequiredFieldValidator ID="ShipToNumRequired" runat="server"
                                        ControlToValidate="ShipToNum" ErrorMessage="Ship To # is required."
                                        ToolTip="Ship To # is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell ColumnSpan="2">
                                    <asp:CompareValidator ID="PasswordCompare" runat="server"
                                        ControlToCompare="Password" ControlToValidate="ConfirmPassword"
                                        Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match." ValidationGroup="CreateUserWizard1" />
                                </asp:TableCell>
                            </asp:TableRow>
                            <asp:TableRow>
                                <asp:TableCell ColumnSpan="2" Style="color: red;">
                                    <asp:Literal EnableViewState="False" ID="ErrorMessage" runat="server" />
                                </asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>
                    </ContentTemplate>
                </asp:CreateUserWizardStep>
                <asp:WizardStep id="AssignUserToRoles" runat="server"
                    AllowReturn="False" Title="Assign User To Roles"
                    OnActivate="AssignUserToRoles_Activate" OnDeactivate="AssignUserToRoles_Deactivate">
                    <asp:Table id="CreateUser" runat="server"
                        Width="100%" CellPadding="0" CellSpacing="0" BackColor="#D7D7D7">
                        <asp:TableRow>
                            <asp:TableCell Width="100%" HorizontalAlign="center" Style="color: black;">
                                <asp:Label id="lblAssignRoles" runat="server"
                                    Text="Select a role for the user." />
                            </asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableCell Width="100%" HorizontalAlign="center">
                                <asp:ListBox id="AvailableRoles" runat="server" />
                            </asp:TableCell>
                        </asp:TableRow>
                    </asp:Table>
                </asp:WizardStep>
                <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
                </asp:CompleteWizardStep>
            </WizardSteps>
        </asp:CreateUserWizard>
    </div>
</form>
</body>
</html>
 
Old July 2nd, 2007, 04:14 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 Talarin,

You haven't hooked up the CreateUserWizard1_CreatedUser method to the CreatedUser event of the control. Either set up the handler in the ASPX portion of the site (as I think is the case with Scott's C# example) or add a Handles clause to your method which is how VB does it by default. E.g.:

Protected Sub CreateUserWizard1_CreatedUser(...) Handles CreateUserWizard1.CreatedUser

Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old July 3rd, 2007, 07:26 AM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow, I can't tell you how many times I looked over that code, especially that sub, and didn't pick that up. I feel quite foolish Thank you Imar, that was exactly the problem.

-Tal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Profiles and DALs plb BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 January 25th, 2007 01:07 PM
Profiles and Shopping Cart ohphoto BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 November 6th, 2006 05:56 AM
Profiles and Membership Pettman ASP.NET 2.0 Basics 2 March 1st, 2006 04:23 AM
Member Profiles Ben Horne Forum and Wrox.com Feedback 4 March 3rd, 2004 02:11 PM
Forum profiles nebbish Forum and Wrox.com Feedback 1 June 3rd, 2003 05:23 PM





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