OH NO! Another Create User Wizard Additional Fields Question:(

Rate It (1)

Last post 08-25-2009 8:59 PM by Bobby-Z. 20 replies.

Sort Posts:

  • OH NO! Another Create User Wizard Additional Fields Question:(

    01-25-2009, 2:09 AM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

    Yes it is.

    Most of the forums and vidoes and tutorial are about adding another step to the wizard, but most of us normal business owners want a one-page sign-up process and ASP.NEt Developers (if you are reading this) we business owners want a Create User Wizard that collects Customer Information, You could call it the CompleteCreateUserWizard complete with Name, address, Phone Number, City, State, Zip - you know for billing purposes. But like most visitors people want things short and sweet - one page forms, one-click purchasing etc.  So maybe in .NET 4.0 we can get a Complete CreateUserWizard or simple code to implement it.

     Now to my question.

    I have added a one-page createuserwizard form, I have added several fields including contact and billing info. I have created a customerinfo table to the database with the appropriate columns, The VB codebehind will recognize the Original Create User Wizard textbox ID's but not the ones I added - Why Not - I get the undefined error message

    For a sample of my form visit http://www.mycleaningsolution.com/createBusinessUser.aspx This is how I want it and it took some time to get it right, I do not want to add another step, but I cannot figur out why the SQL insert command statements call the textboxes undefined.

     

    Protected Sub CreateBusinessUser_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateBusinessUser.CreatedUser
    
              Roles.AddUserToRole(CreateBusinessUser.UserName, "business")
    
              Dim InfoDataSource As New SqlDataSource()
              InfoDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("msdbdataConnectionString").ToString()
    
              InfoDataSource.InsertCommandType = SqlDataSourceCommandType.Text
              InfoDataSource.InsertCommand = "INSERT INTO customers.business (CompanyName, FirstName, LastName, Title, Phone, Ext, Email, Address, Suite, City, State, ZipCode, Website, CustomerType) VALUES (@CompanyName, @FirstName, @LastName, @Title, @Phone, @Ext, @Email, @Address, @Suite, @City, @State, @ZipCode, @Website, @CustomerType)"
              InfoDataSource.InsertParameters.Add("CompanyName", txtCompanyName.Text)
              InfoDataSource.InsertParameters.Add("FirstName", txtFirstName.Text)
              InfoDataSource.InsertParameters.Add("LastName", txtLastName.Text)
              InfoDataSource.InsertParameters.Add("Title", txtTitle.Text)
              InfoDataSource.InsertParameters.Add("Phone", txtPhone.Text)
              InfoDataSource.InsertParameters.Add("Ext", txtExt.Text)
              InfoDataSource.InsertParameters.Add("Email", txtEmail.Text)
              InfoDataSource.InsertParameters.Add("Address", txtAddress.Text)
              InfoDataSource.InsertParameters.Add("Suite", txtSuite.Text)
              InfoDataSource.InsertParameters.Add("City", txtCity.Text)
              InfoDataSource.InsertParameters.Add("State", txtState.Text)
              InfoDataSource.InsertParameters.Add("ZipCode", txtZipCode.Text)
              InfoDataSource.InsertParameters.Add("Website", txtWebsite.Text)
              InfoDataSource.InsertParameters.Add("CustomerType", "business")
    
              Dim notification As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
    
              notification.From = New System.Net.Mail.MailAddress("robert.hall@mycleaningsolution.com")
              notification.To.Add(New System.Net.Mail.MailAddress("17146126186@messaging.sprintpcs.com"))
              notification.Priority = Net.Mail.MailPriority.High
              notification.Subject = "New Subscription"
              notification.Body = " A New Business User Has Created An Account"
    
              Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
              smtpClient.Send(notification)
    
              Dim contact As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
    
              contact.From = New System.Net.Mail.MailAddress("robert.hall@mycleaningsolution.com")
              contact.To.Add(New System.Net.Mail.MailAddress("robert.hall@mycleaningsolution.com"))
              contact.Priority = Net.Mail.MailPriority.High
              contact.Subject = "New User"
              contact.Body = " A New Business User Has Created An Account"
    
              Dim smtpClient2 As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
              smtpClient2.Send(contact)
    End Sub

     As You can see the Create User Button adds them to the role of business, then inserts the extra info, then emails and sends me a textmessage that a user has been created so i can contact them personally as soon as possible.

    All except for the InsertParameter Textbox.Text - it works fine, but it wont recognize the values from the textboxes to insert into the database.

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    01-25-2009, 9:27 AM
    • All-Star
      35,766 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,791

     The problem is you need to use .FindControl() to find the controls inside the wizard.

     This is how is solved it when I had to do this: (c#)

     

    TextBox NameTextBox = (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Name");

      

    To find a control contained in this markup:

     

        <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 
            LoginCreatedUser="False" 
            oncreateduser="CreateUserWizard1_CreatedUser" ContinueDestinationPageUrl="~/Admin/Reports/CreateReport.aspx">
            <WizardSteps>
                <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" 
                    Title="Login Details">
                    <ContentTemplate>
                        <table border="0">
                            <tr>
                                <td align="right">
                                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
                                        ControlToValidate="UserName" ErrorMessage="User Name is required." 
                                        ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                        ControlToValidate="Password" ErrorMessage="Password is required." 
                                        ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="ConfirmPasswordLabel" runat="server" 
                                        AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" 
                                        ControlToValidate="ConfirmPassword" 
                                        ErrorMessage="Confirm Password is required." 
                                        ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="Label3" runat="server" AssociatedControlID="Name">Name:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="Name" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                        ControlToValidate="Name" ErrorMessage="Namme is required." 
                                        ToolTip="Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>                        
                            <tr>
                                <td align="right">
                                    <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="Email" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="EmailRequired" runat="server" 
                                        ControlToValidate="Email" ErrorMessage="E-mail is required." 
                                        ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="Label4" runat="server" AssociatedControlID="CompanyName">Company Name:</asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox ID="CompanyName" runat="server"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                        ControlToValidate="CompanyName" ErrorMessage="Company name is required." 
                                        ToolTip="Company name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>                        
                            <tr>
                                <td align="center" colspan="2">
                                    <asp:CompareValidator ID="PasswordCompare" runat="server" 
                                        ControlToCompare="Password" ControlToValidate="ConfirmPassword" 
                                        Display="Dynamic" 
                                        ErrorMessage="The Password and Confirmation Password must match." 
                                        ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color:Red;">
                                    <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:CreateUserWizardStep>
                <asp:CompleteWizardStep AllowReturn="false" ID="CompleteWizardStep1" runat="server">
                </asp:CompleteWizardStep>
            </WizardSteps>
        </asp:CreateUserWizard>
      
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    01-25-2009, 10:12 AM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

    So this is what i did based upon the info you gave me:

      

    Dim CN As TextBox = CType(CreateBusinessUser.CreateUserStep.FindControl("txtCompanyName"), TextBox)
    
    InfoDataSource.InsertParameters.Add("CompanyName", CN.Text)

     It showed no errors in the code, but when i submitted I received this error

    Object reference not set to an instance of an object

    Is that to do with my db connection? or is it that I am just declaring a cast-type and not trying to find the control?

    It is saving the info from the original create user wizard, but I get an error at the insert parameters , and none of the validation controls work in the new section, should I forget the wizard, make my own form and deal with the database connections another way?

     BTW: I was in no way complaining about ASP.NET - the Best!

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-02-2009, 10:20 PM
    • Member
      55 point Member
    • asp2go
    • Member since 08-26-2008, 11:42 PM
    • Posts 61

    That error is often the result of a simple coding error (spelling, non-declared variable etc.). Check over your code carefully (hard after you've stared at it so long I know!).

     You could also try putting breakpoints throughout the sub and see exactly where the issue is.

    The wizard will do the job just fine with additional fields so if you're close I'd keep going rather than 'roll your own'. Agreed that it would be nice to have asp.net include more options but the flexibility is there to add any fields we want in any manner we want and tie it to the wizard. I am intercepting the Creating User event as well to bypass the additional step of "complete" that is autogenerated to get the single page you are referring to.

  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-06-2009, 1:56 PM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

    I am still having issues with it:

     I am getting an error message, but it still enters the new user in the aspnet_Users and membership tables, and it enters the data into usersinroles table, I even created a table called customer ID, and added an insert procedure into the stored procedure for asp_net create user, and I get the userID linked to the Customer ID, but when it comes to the information not contained in the membership namespace, I get no entry into customer_info table.

     

    Protected Sub CreateUserButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles CreateUserButton.Click
    
              'Create A New User
              Dim createStatus As MembershipCreateStatus
              Dim newUser As MembershipUser = Membership.CreateUser(UserName.Text, Password.Text, Email.Text, Question.Text, Answer.Text, True, createStatus)
    
              Select Case createStatus
                   Case MembershipCreateStatus.Success
                   SucessLabel.Text = "Your New Account has been set-up and is Activated!"
                   ThankYouLabel.Text = "Thank-You"
                   AddUserToRole()
                   AddExtraInfo()
                   Case MembershipCreateStatus.DuplicateUserName
                   ErrorMessage.Text = "User Name Already Exists, Please Select Another User Name"
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.DuplicateEmail
                   ErrorMessage.Text = "A User with That Email Address Already Exists."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.InvalidEmail
                   ErrorMessage.Text = "That is not a valid Email Address."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.InvalidPassword
                   ErrorMessage.Text = "The Password You Entered is Not Valid. Password Must be a Minimum of 7 Characters with 1 non-Alphanumeric Character."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case Else
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"
    
              End Select
    End Sub
         Private Sub AddUserToRole()
              Roles.AddUserToRole(UserName.Text, "customer")
         End Sub
    
         Private Sub AddExtraInfo()
              Dim InfoDataSource As New SqlDataSource()
              InfoDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString1").ToString()
    
              InfoDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure
              InfoDataSource.InsertCommand = "Add_CustomerInfo"
              InfoDataSource.InsertParameters.Add("CompanyName", txtCompanyName.Text)
              InfoDataSource.InsertParameters.Add("FirstName", txtFirstName.Text)
              InfoDataSource.InsertParameters.Add("LastName", txtLastName.Text)
              InfoDataSource.InsertParameters.Add("Title", txtTitle.Text)
              InfoDataSource.InsertParameters.Add("Phone", txtPhone.Text)
              InfoDataSource.InsertParameters.Add("Ext", txtExt.Text)
              InfoDataSource.InsertParameters.Add("Email", txtEmail.Text)
              InfoDataSource.InsertParameters.Add("Address", txtAddress.Text)
              InfoDataSource.InsertParameters.Add("Suite", txtSuite.Text)
              InfoDataSource.InsertParameters.Add("City", txtCity.Text)
              InfoDataSource.InsertParameters.Add("State", txtState.Text)
              InfoDataSource.InsertParameters.Add("ZipCode", txtZipCode.Text)
              InfoDataSource.InsertParameters.Add("Website", txtWebsite.Text)
              'InfoDataSource.InsertParameters.Add("CustomerSince", DateTime.Now())
     
     
    ALTER PROCEDURE dbo.Add_CustomerInfo
    	
    	@CustomerID int,
    	@CompanyName varchar(50),
    	@FirstName varchar(50),
    	@LastName varchar(50),
    	@Title varchar(50),
    	@OfficePhone nvarchar(20),
    	@Ext varchar(5),
    	@CellPhone nvarchar(20),
    	@Email nvarchar(256),
    	@Address varchar(50),
    	@Suite varchar(10),
    	@City varchar(50),
    	@State varchar(2),
    	@ZipCode smallint,
    	@Website nvarchar(256),
    	@CusomerSince smalldatetime OUTPUT
    	
    AS
    	INSERT customer_info (CustomerID, CompanyName, FirstName, LastName, Title, OfficePhone, Ext, Cellphone, Email, Address, Suite, City, State, ZipCode, Website, CustomerSince)
        VALUES (@CustomerID, @CompanyName, @FirstName, @LastName, @Title, @OfficePhone, @Ext, @CellPhone, @Email, @Address, @Suite, @City, @State, @ZipCode, @Website, GetDate())
        
    	RETURN
     
     I also run it in trace and it jumps right through the addExtraInfo() function, but no record. I also thought it might be the connection string, I saw this code in one of the videos (SQL)
    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-06-2009, 2:42 PM
    • Member
      55 point Member
    • asp2go
    • Member since 08-26-2008, 11:42 PM
    • Posts 61

    Bobby-z,

    What is the error message? To me it looks like the addExtraInfo function should have a parameter passed to it? I assume that this is a separate table with a foreign key to the aspnet_users table? If so you'd need to first pass the userID to the function so that it can properly set the FK relationship (i.e. something like addExtraInfo(userID) which your function would then use - it currently can look up all the data from the UI for everything except the userID which needs to be retrieved from the create user function.

    Let me know if this helps. I am using a custom Table Profile Provider which makes capturing this information easier but your custom function looks close to working.

  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-07-2009, 1:15 AM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

    I dont know if it is related, but it is from one of the cases in the first section. I enter a new user  and new info, hit create user, but the case does not give the success label, but the "use a different question message" from another case. even though it was a success. I don't know if that is related.

    I have a different setup, I have a table I created that has two columns, UserId and CustomerID, The CustomerID is an identity int seed 1, and the UserId is keyed to aspnet_createuser. I added this to the aspnet_membership_createuser

    INSERT INTO dbo.customers_id ( UserId )

    VALUES (@UserId )

    It works, after I create a user, it creates a customer id integer.

    This is probably where my problem is because the UserInformation table is keyed to 'CustomerID'. So I need to call up this new customer id and then  pass all the info into the new table! probably since the 'CustomerID' field in the UserInfo table is not null, but shouldn't I be getting a null field error?

    and how would I then in VB code retrieve that new 'CustomerID' to now submit it with all the rest into the new table? So my problem is I probably missed a step.

    explanation: why I have a separate table to create a customerID. I have 3 classes of customers, with different types of information, but did not want duplicate customerID's in the three separate customer info tables. I also have 3 different forms to create a user depending upon which type of customer they are (ie residential customers do not need a company name or phone ext, or contact title, and real estate agents have one office with several agents). and to make matters worse, I am going to add another user account type for employment applicants.

    Does this make it any cleaer?

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-08-2009, 2:06 AM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

    OK I got it to work, but now I still have another issue. The Success Label displays 'Duplicate User Message, Account not created' even though it has been created and stored. It is like it submits it twice, and I need to add a condition, because it records the information again and again in my customer Table if you keep hitting submit because of the error message.

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-08-2009, 4:14 PM
    • Member
      55 point Member
    • asp2go
    • Member since 08-26-2008, 11:42 PM
    • Posts 61

    To retrieve the ID field you'll need to either use Scope_Identity() or set an Output parameter to return the value back to the calling code.

    Maybe post the code as revised and we can try to determine where the issue is with the duplicate issue.

    In your customer table you should consider setting a unique index on the userId field to have the database prevent duplicate entries into the customer table in error.

  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-10-2009, 3:21 AM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

     

    Protected Sub CreateUserButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles CreateUserButton.Click
    
              'Create A New User
              Dim createStatus As MembershipCreateStatus
              Dim newUser As MembershipUser = Membership.CreateUser(UserName.Text, Password.Text, Email.Text, Question.Text, Answer.Text, True, createStatus)
    
    
              Select Case createStatus
                   Case MembershipCreateStatus.Success
                   AddUserToRole()
                   AddExtraInfo()
                   Notify()
                   SucessLabel.Text = "Your New Account has been set-up and is Activated!"
                   ThankYouLabel.Text = "Thank-You"
                   Case MembershipCreateStatus.InvalidUserName
                   ErrorMessage.Text = "That is an Invalid User Name."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.InvalidPassword
                   ErrorMessage.Text = "The Password You Entered is Not Valid. Password Must be a Minimum of 7 Characters with 1 non-Alphanumeric Character."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.InvalidQuestion
                   ErrorMessage.Text = "That is not a valid Question."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.InvalidAnswer
                   ErrorMessage.Text = "That is not a valid Answer."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.InvalidEmail
                   ErrorMessage.Text = "That is not a valid Email Address."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.DuplicateUserName
                   ErrorMessage.Text = "User Name Already Exists, Please Select Another User Name"
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.DuplicateEmail
                   ErrorMessage.Text = "A User with That Email Address Already Exists."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.UserRejected
                   ErrorMessage.Text = "We are sorry but we cannot create your account at this time."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"
                   Case MembershipCreateStatus.InvalidProviderUserKey
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"
                   Case MembershipCreateStatus.DuplicateProviderUserKey
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"
                   Case MembershipCreateStatus.ProviderError
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"
                   Case Else
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"
    
              End Select
    End Sub
         Private Sub AddUserToRole()
              Roles.AddUserToRole(UserName.Text, "construction")
         End Sub
    
         Private Sub AddExtraInfo()
              Dim customerType As String = "Construction"
              Dim newUser2 As MembershipUser = Membership.GetUser(UserName.Text)
              Dim newUserId As Guid = CType(newUser2.ProviderUserKey, Guid)
    
              Dim InfoDataSource As String = ConfigurationManager.ConnectionStrings("ASPNETDBConnectionString1").ConnectionString
              Dim insertSql As String = "INSERT INTO customers (UserID, CompanyName, FirstName, LastName, Title, Phone, Ext, CellPhone, EmailAddress, Address, Suite, City, State, ZipCode, Website, CustomerSince, CustomerType) VALUES (@UserID, @CompanyName, @FirstName, @LastName, @Title, @Phone, @Ext, @CellPhone, @EmailAddress, @Address, @Suite, @City, @State, @ZipCode, @Website, GetDate(), @CustomerType)"
              Using myConnection As New SqlConnection(InfoDataSource)
              Dim myCommand As New SqlCommand(insertSql, myConnection)
              myConnection.Open()
    
               myCommand.Parameters.AddWithValue("@UserID", newUserId)
               myCommand.Parameters.AddWithValue("@CompanyName", txtCompanyName.Text)
               myCommand.Parameters.AddWithValue("@FirstName", txtFirstName.Text)
               myCommand.Parameters.AddWithValue("@LastName", txtLastName.Text)
               myCommand.Parameters.AddWithValue("@Title", txtTitle.Text)
               myCommand.Parameters.AddWithValue("@Phone", txtPhone.Text)
               myCommand.Parameters.AddWithValue("@Ext", txtExt.Text)
               myCommand.Parameters.AddWithValue("@CellPhone", txtCellPhone.Text)
               myCommand.Parameters.AddWithValue("@EmailAddress", txtEmail.Text)
               myCommand.Parameters.AddWithValue("@Address", txtAddress.Text)
               myCommand.Parameters.AddWithValue("@Suite", txtSuite.Text)
               myCommand.Parameters.AddWithValue("@City", txtCity.Text)
               myCommand.Parameters.AddWithValue("@State", txtState.Text)
               myCommand.Parameters.AddWithValue("@ZipCode", txtZipCode.Text)
               myCommand.Parameters.AddWithValue("@Website", txtWebsite.Text)
               myCommand.Parameters.AddWithValue("@CustomerType", customerType)
    
              myCommand.ExecuteNonQuery()
              myConnection.Close()
              End Using
         End Sub
    
    Private Sub Notify()
    
              Dim notification As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
    
              notification.From = New System.Net.Mail.MailAddress("xxxxx@mycleaningsolution.com")
              notification.To.Add(New System.Net.Mail.MailAddress("xxxxx@messaging.sprintpcs.com"))
              notification.Priority = Net.Mail.MailPriority.High
              notification.Subject = "New Subscription"
              notification.Body = " A New Business User Has Created An Account"
    
              Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
              smtpClient.Send(notification)
    
              Dim contact As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
    
              contact.From = New System.Net.Mail.MailAddress("xxxxx@mycleaningsolution.com")
              contact.To.Add(New System.Net.Mail.MailAddress("xxxxx@mycleaningsolution.com"))
              contact.Priority = Net.Mail.MailPriority.High
              contact.Subject = "New User"
              contact.Body = " A New Business User Has Created An Account"
    
              Dim smtpClient2 As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
              smtpClient2.Send(contact)
    End Sub

     This is as it stands now.

    I bypassed the customerID table, and made a customer table that has nulls for the columns that aren't needed for certain clients, instead I added a customerType field to enable me to view users based upon customer type.  but I do want to fix the error with the form being submitted and recorded, but getting an error and then people trying to resubmit, and getting a duplicate recording.

    It is something wring with the Select Case section, because it should only record the info if it is successful.

    also, in the contact.body("") email section, is there a way to make a multiple line body (line breaks)? do you just add another contact.body line?

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-11-2009, 12:09 AM
    • Member
      55 point Member
    • asp2go
    • Member since 08-26-2008, 11:42 PM
    • Posts 61

    In VB you can use &vbcrlf to denote line breaks if it is not an Html formatted mail message. Otherwise it will wrap.

    You can alternatively use Html formatting within the mail message either set programmatically as you have done OR define an Html body file that can be inserted into the message - ideally with tags so that you can replace Welcome <% NameHere %> with Welcome Jim in the message all formatted nicely as required.

    HTH.

  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-11-2009, 12:29 AM
    Answer
    • Member
      55 point Member
    • asp2go
    • Member since 08-26-2008, 11:42 PM
    • Posts 61

    Bobby-Z:
     but I do want to fix the error with the form being submitted and recorded, but getting an error and then people trying to resubmit, and getting a duplicate recording. 

    It is something wring with the Select Case section, because it should only record the info if it is successful.

    Can you clarify what is happening here? Is this a duplicate user message or you getting duplicate company data?

  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-14-2009, 1:45 AM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

    I am entering a username I know does not exist. I submit and all information gets recorded, but instead of the case.success, I am getting the case.duplicateuser error.

    When I see the error, I hit submit again, and get the duplicateuser error again, but it then records another record in the AddExtraInfo() Table, which should only happen in the case.success section.

    So the user keeps getting the error message and keeps hitting submit, and I get one user created, but multiple (many) AddExtraInfo() entries.

    As you can see the AddExtraInfo() sub is nested in the case.success section, so it should not record info unless the MembershipCreateUser was a success.

    (the error message is displayed on the asp:labels)

    I would post it to the web, but my web server doesn't have sql server setup yet. - I no longer have this in a wizard anymore.

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-16-2009, 12:58 AM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

    OK Thanks to ASP2GO everything works fine, except I am still having a problem with the Select Case section.

    I create a new user, all info gets stored - I know it is a unique user - but I still get displayed the error message after submission of

    'Duplicate User Message, Account not created'  from the case #6 when I should be getting the success notification.

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
  • Re: OH NO! Another Create User Wizard Additional Fields Question:(

    02-16-2009, 5:35 PM
    • Member
      648 point Member
    • Bobby-Z
    • Member since 10-04-2008, 5:53 AM
    • Orange County, CA
    • Posts 284

    OK For those of you who want to add additional info to the create user wizard, the easiest way is to use the membership system but create your own form.

    Since I had so much trouble doing it I will post the code here and you can copy it for yourself. 

    Setup: I have 3 sections

    1. The CreateUser section which is utilized by aspnet_Membership - Utilizes the aspnet_Users table and aspnet_Membership table - The textbox names that the wizard uses I used.

    2. Personal Information - Information about the new User - Utilizes a table named customers_personal

    3. Notify Section - Emails and Text messages me, and sends a confirmation email to the new user.

    I also add the new user to a role.

    Protected Sub CreateUserButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles CreateUserButton.Click

              'Create A New User in aspnet_Membership
              Dim createStatus As MembershipCreateStatus
              Dim newUser As MembershipUser = Membership.CreateUser(UserName.Text, Password.Text, Email.Text, Question.Text, Answer.Text, True, createStatus)

              'Error Checking
              Select Case createStatus
                   Case MembershipCreateStatus.Success
                   AddExtraInfo()
                   AddUserToRole()
                   Notify()
                   Response.Redirect("AccountCreated.aspx")

                   Case MembershipCreateStatus.InvalidUserName
                   ErrorMessage.Text = "That is an Invalid User Name."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"

                   Case MembershipCreateStatus.InvalidPassword
                   ErrorMessage.Text = "The Password You Entered is Not Valid. Password Must be a Minimum of 7 Characters with 1 non-Alphanumeric Character."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"

                   Case MembershipCreateStatus.InvalidQuestion
                   ErrorMessage.Text = "That is not a valid Question."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"

                   Case MembershipCreateStatus.InvalidAnswer
                   ErrorMessage.Text = "That is not a valid Answer."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"

                   Case MembershipCreateStatus.InvalidEmail
                   ErrorMessage.Text = "That is not a valid Email Address."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"

                   Case MembershipCreateStatus.DuplicateUserName
                   ErrorMessage.Text = "User Name Already Exists, Please Select Another User Name"
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"

                   Case MembershipCreateStatus.DuplicateEmail
                   ErrorMessage.Text = "A User with That Email Address Already Exists."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"

                   Case MembershipCreateStatus.UserRejected
                   ErrorMessage.Text = "We are sorry but we cannot create your account at this time."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Check Error Message"

                   Case MembershipCreateStatus.InvalidProviderUserKey
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"

                   Case MembershipCreateStatus.DuplicateProviderUserKey
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"

                   Case MembershipCreateStatus.ProviderError
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"

                   Case Else
                   ErrorMessage.Text = "Unknown Error Occured, Please Try Again."
                   SucessLabel.Text = "Your New Account has not been created!"
                   ThankYouLabel.Text = "Please Try Again"

              End Select
    End Sub
         Private Sub
    AddUserToRole()
              'Add the new user to a role - optional
              Roles.AddUserToRole(UserName.Text, "[role name]")
         End Sub

         Private Sub
    AddExtraInfo()
              'Declare the customerType
              Dim customerType As String = "Personal"

              'Get the UserID
              Dim newUser As MembershipUser = Membership.GetUser(UserName.Text)
              Dim newUserId As Guid = CType(newUser.ProviderUserKey, Guid)

              'Open the connection
              Dim DataSource As String = ConfigurationManager.ConnectionStrings("[InsertYourConnectionStringHere]").ConnectionString
              Using myConnection As New SqlConnection(DataSource)
              myConnection.Open()

              'Add userID to Customer_id table to create a numeric CustomerID - Stored Procedure then retrieve that new CustomerID to put into the customers info table
              Dim selectSQL As New SqlCommand("RetrieveCustomerId", myConnection)
              selectSQL.CommandType = Data.CommandType.StoredProcedure
              selectSQL.Parameters.AddWithValue("@UserId", newUserId)
              Dim NewCustomerID As Integer = (selectSQL.ExecuteScalar())

              'Insert Additional Info into customers_personal Table
              Dim insertSql As String = "INSERT INTO customers.personal (CustomerID, FirstName, LastName, SpouseName, Phone, CellPhone, Address, Apt, City, State, ZipCode, CustomerSince, BirthDate, Anniversary, Email) VALUES (@CustomerID, @FirstName, @LastName, @SpouseName, @Phone, @CellPhone, @Address, @Apt, @City, @State, @ZipCode, GetDate(), @BirthDate, @Anniversary, @Email)"

              Dim myOtherCommand As New SqlCommand(insertSql, myConnection)
              myOtherCommand.Parameters.AddWithValue("@CustomerID", NewCustomerID)
              myOtherCommand.Parameters.AddWithValue("@FirstName", txtFirstName.Text)
              myOtherCommand.Parameters.AddWithValue("@LastName", txtLastName.Text)
              myOtherCommand.Parameters.AddWithValue("@SpouseName", txtSpouse.Text)
              myOtherCommand.Parameters.AddWithValue("@Phone", txtPhone.Text)
              myOtherCommand.Parameters.AddWithValue("@CellPhone", txtCellPhone.Text)
              myOtherCommand.Parameters.AddWithValue("@Address", txtAddress.Text)
              myOtherCommand.Parameters.AddWithValue("@Apt", txtSuite.Text)
              myOtherCommand.Parameters.AddWithValue("@City", txtCity.Text)
              myOtherCommand.Parameters.AddWithValue("@State", txtState.Text)
              myOtherCommand.Parameters.AddWithValue("@ZipCode", txtZipCode.Text)
              myOtherCommand.Parameters.AddWithValue("@Email", txtEmail.Text)
              myOtherCommand.Parameters.AddWithValue("@BirthDate", BirthMonth.SelectedValue)
              myOtherCommand.Parameters.AddWithValue("@Anniversary", Anniversary.SelectedValue)
              myOtherCommand.ExecuteNonQuery()
              myConnection.Close()
              End Using
         End Sub

    Private Sub
    Notify()

              'Send Me a Text Message
              Dim notification As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
                   notification.From = New System.Net.Mail.MailAddress("address@mycleaningsolution.com")
                   notification.To.Add(New System.Net.Mail.MailAddress("mobilephone#@messaging.sprintpcs.com"))
                   notification.Priority = Net.Mail.MailPriority.High
                   notification.Subject = "New User"
                   notification.Body = " A New Business User Has Created An Account"

              Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
              smtpClient.Send(notification)

              'Send Me an Email
              Dim contact As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
                   contact.From = New System.Net.Mail.MailAddress("address@mycleaningsolution.com")
                   contact.To.Add(New System.Net.Mail.MailAddress("address@mycleaningsolution.com"))
                   contact.Priority = Net.Mail.MailPriority.High
                   contact.Subject = "New User"
                   contact.Body = " A New Business User Has Created An Account"

              Dim smtpClient2 As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
              smtpClient2.Send(contact)

              'Send Acknowledgement Email to Customer
              Dim verify As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
                   verify.From = New System.Net.Mail.MailAddress("newuser@mycleaningsolution.com")
                   verify.To.Add(New System.Net.Mail.MailAddress(Email.Text))
                   verify.Priority = Net.Mail.MailPriority.Normal
                   verify.Subject = "New User Account Created"
                   verify.Body = " Your New User Account has been created for " + UserName.Text + " at http://www.MyCleaningSolution.com"

              Dim smtpClient3 As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
              smtpClient3.Send(verify)
    End Sub

     This is the Stored Procedure to retrieve the CustomerID

    ALTER PROCEDURE RetrieveCustomerID
    
    	(
    	@UserId uniqueidentifier
    	)
    AS
    
    INSERT INTO customer_id (UserId)
    VALUES (@UserId)
    
    
    SELECT SCOPE_IDENTITY()

     It inserts the New UserId into the table which has a primary key of CustomerID as an int Identity that increments by 1 everytime. If you have only one table for collecting customer information, you can skip this step. I have separate tables for company and personal clients and need to make sure I do not get two sets of CustomerID's (basically a Customer#)

    Obviously, the customerID table, the AddUsertoRole, and the email notification are all optional

    "Success is the Sum of Small Efforts, Repeated Day in and Day Out - Without Ceasing!"

    Robert Hall
    CEO and Founder
    My Service Solutions, Inc.
Page 1 of 2 (21 items) 1 2 Next >