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 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register | FAQ | Members List | Calendar | 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 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
Thread Tools Display Modes
  #1 (permalink)  
Old June 11th, 2013, 05:33 PM
Authorized User
Points: 207, Level: 4
Points: 207, Level: 4 Points: 207, Level: 4 Points: 207, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2012
Posts: 40
Thanks: 8
Thanked 5 Times in 4 Posts
Default Dropdownlist in createuser wizard.

Hi Imar this has really driven me nutts, please help!!
I am trying to implement dropdownlist inside createuserwizard to get user choice and then programatically insert it in the database.

  <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
                                <asp:TextBox ID="UserName" CssClass="textboxStyle" runat="server" 
                                    ToolTip="User Name"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                    ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                    ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                <asp:TextBox ID="Password" CssClass="textboxStyle" runat="server" 
                                    TextMode="Password" ToolTip="Password"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                    ControlToValidate="Password" ErrorMessage="Password is required." 
                                    ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                <asp:TextBox ID="ConfirmPassword" CssClass="textboxStyle" runat="server" 
                                    TextMode="Password" ToolTip="Confirm Password"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" 
                                    ErrorMessage="Confirm Password is required." 
                                    ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                <asp:TextBox ID="Email" CssClass="textboxStyle" runat="server" 
                                <asp:RequiredFieldValidator ID="EmailRequired" runat="server" 
                                    ControlToValidate="Email" ErrorMessage="E-mail is required." 
                                    ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                       <p>Please identify yourself in one of the following:</p>
                           <asp:DropDownList ID="DropDownList1" runat="server">
                               <asp:ListItem>Vice Principal</asp:ListItem>
                               <asp:ListItem>Clerkial Staff</asp:ListItem>
                               <asp:ListItem>Other Staff</asp:ListItem>
                                <asp:RequiredFieldValidator ID="identityRequired" runat="server" 
                                    ControlToValidate="DropDownList1" ErrorMessage="Identification in one of the categories is required." 
                                    ToolTip="Identification is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

                            <td align="center">
                                <asp:CompareValidator ID="PasswordCompare" runat="server" 
                                    ControlToCompare="Password" ControlToValidate="ConfirmPassword" 
                                    ErrorMessage="The Password and Confirmation Password must match." 
                            <td align="center" style="color:Red;">
                                <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                    <table border="0" cellspacing="5" style="width:100%;height:100%;">
                        <tr align="right">
                            <td align="left" colspan="0">
                                <asp:Button ID="StepNextButton" CssClass="buttonStyle" runat="server" CommandName="MoveNext" 
                                    Text="Create User" ValidationGroup="CreateUserWizard1" />


protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        TextBox Category = DropDownList1.SelectedValue;

        // Get the UserId of the just-added user
        MembershipUser newUser = Membership.GetUser(CreateUserWizard1.UserName);
        Guid newUserId = (Guid)newUser.ProviderUserKey;

        // Insert a new record into UserProfiles
        string connectionString =
        string insertSql = "INSERT INTO UserDetails(UserId, FirstName, MiddleName, LastName, HomeTown, Category) VALUES(@UserId, @FirstName, @MiddleNAme, @LastName, @HomeTown, @Category)";

        using (SqlConnection myConnection = new SqlConnection(connectionString))
            SqlCommand myCommand = new SqlCommand(insertSql, myConnection);
            myCommand.Parameters.AddWithValue("@UserId", newUserId);
            myCommand.Parameters.AddWithValue("@FirstName", DBNull.Value);
            myCommand.Parameters.AddWithValue("@MiddleName", DBNull.Value);
            myCommand.Parameters.AddWithValue("@LastName", DBNull.Value);
            myCommand.Parameters.AddWithValue("@HomeTown", DBNull.Value);
            myCommand.Parameters.AddWithValue("@Category", Category.Text.Trim());

Error: DropList1 doesn't exist in this context.


Last edited by 07Raghav; June 11th, 2013 at 05:42 PM.
Reply With Quote
  #2 (permalink)  
Old June 11th, 2013, 08:31 PM
Authorized User
Points: 207, Level: 4
Points: 207, Level: 4 Points: 207, Level: 4 Points: 207, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2012
Posts: 40
Thanks: 8
Thanked 5 Times in 4 Posts

ok I seem to have finally found a solution but don't know about its validity.

DropDownList category = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownList1");
Please sir look into it and can i use it for further usage.


Last edited by 07Raghav; June 11th, 2013 at 08:34 PM.
Reply With Quote
  #3 (permalink)  
Old June 14th, 2013, 09:17 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,052
Thanks: 80
Thanked 1,581 Times in 1,558 Posts

Hi there,

yes, this is the right approach to find a control in an editable control.


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

Thread Tools
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
CreateUser Wizard sophia BOOK: Beginning ASP.NET 4 : in C# and VB 25 April 23rd, 2012 04:10 AM
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
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

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

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