locked
Problem with Custom CreateUserWizard RRS feed

  • Question

  • User732704340 posted

    Hi,

    I've added a CreateWizardStep to the beginning of the process with one textbox and a button because before a user can go through the standard registration process they have to provide a  customer ID (they can get it only by visiting the store and speak to customer service), which is then compared to two tables (customers and customersOnline) in database B (additional).

    The first condition is that the customers table has to consists of the particular ID because it keeps all IDs that have been given to customers as well as other information (name, postcode, etc). If the ID doesn't exists a user can't register.

    The second condition checks the customersOnline table (it has only one column: customerOnline_ID), which has to be empty to allow a user to register (given ID doesn't exist). If the ID is found in that table it means that the user already registered to online service. If it's empty and the first condition has been also met the textbox should pass the ID to the next step (which normally is the first step of CreateUserWizard that requires username, password, etc) and place it in a textbox without option to edit (just want to save customers inputing ID twice) or even it doesn't have to be visible at all.

    When the user inputs all the required data and press confirm button the ID should be saved in the customersOnline table in database B and the rest of information (actual user account) in a database A, which is the default asp.net database.

    The first problem I've met is that in the first custom step I've added textbox manually and it would be ok but I can't edit the button (It was placed there as default to go to the next step of CreateUserWizard. So the question is if it's possible to edit this button?

     

    Thursday, April 28, 2011 5:22 PM

Answers

  • User-1828494216 posted

    Hi,

    as Decker Dong suggested you should look into SqlDataReader Class. At the end you have samples of C# and VisualBasic.

    protected void CreateUserWizard1_ActiveStepChanged(object sender, EventArgs e)
    {
        if (CreateUserWizard1.ActiveStep.ID == "CreateUserWizardStep1") //CreateUserWizard1.ActiveStepIndex = 1
        {
            string MyValidationString1;
            bool MyValidationString2;
            int MyValidationString3;
    
            string queryString =
            "SELECT OrderID, CustomerID FROM dbo.Orders;";
    
            using (SqlConnection connection =
                    new SqlConnection(connectionString))
            {
                SqlCommand command =
                    new SqlCommand(queryString, connection);
                connection.Open();
    
                SqlDataReader reader = command.ExecuteReader();
    
            // Call Read before accessing data.
                while (reader.Read())
                {
                    MyValidationString1 = reader[0].ToString();
                    MyValidationString2 = (bool)reader[1];
                    MyValidationString3 = (int)reader[2];
                }
    
            // Call Close when done reading.
            reader.Close();
            }
    
            // Now you validate...
    
            if(MyValidationString1 == "SomeString" && MyValidationString2 && MyValidationString3 == 1)
            {
                //let the user go to the next step
            }
            else
            {
                //Validation failed, set current active step to start step
                CreateUserWizard1.ActiveStepIndex = 0
            }
        }
    }
    NOTE: The code is not tested and not optimized, it's just a sample to get you going in the right direction ;)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 30, 2011 6:35 AM

All replies

  • User-1828494216 posted

    In Design window click add/remove wizard step. Add new TemplatedWizardStep. Set SetType to Start... set other properties and click ok.

    now click to Convert to StartNavigationTemplate

    Shrani.si

    you should end up with code like this:

    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server">
        <WizardSteps>
            <asp:TemplatedWizardStep ID="StartTemplate" runat="server" StepType="Start" 
                Title="Start">
            </asp:TemplatedWizardStep>
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
            </asp:CreateUserWizardStep>
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
            </asp:CompleteWizardStep>
        </WizardSteps>
        <StartNavigationTemplate>
            <asp:Button ID="StartNextButton" runat="server" CommandName="MoveNext" 
                Text="Next" />
        </StartNavigationTemplate>
    </asp:CreateUserWizard>

    Friday, April 29, 2011 12:09 AM
  • User-1828494216 posted

    btw. i just realized... u actually don't need to convert to StartNavigationTemplate... you can do all u want in OnActiveStepChanged Event :)

    <asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
    OnActiveStepChanged="CreateUserWizard1_ActiveStepChanged"> <WizardSteps> <asp:TemplatedWizardStep ID="CustomStartStep1" runat="server" StepType="Start" Title="CustomStartStep"> </asp:TemplatedWizardStep> <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server"> </asp:CreateUserWizardStep> <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server"> </asp:CompleteWizardStep> </WizardSteps> </asp:CreateUserWizard>
    protected void CreateUserWizard1_ActiveStepChanged(object sender, EventArgs e)
    {
        if (CreateUserWizard1.ActiveStep.ID == "CreateUserWizardStep1") //CreateUserWizard1.ActiveStepIndex = 1
        {
            //validate
            //if not validated set 
            //CreateUserWizard1.ActiveStepIndex = 0;
        }
    }
    Friday, April 29, 2011 12:17 AM
  • User732704340 posted

    Thanks, I've set it up and it looks good. Any suggestions or ideas how to validate those conditions?

    Friday, April 29, 2011 6:48 AM
  • User3866881 posted

    Hi:)

    Have you tried CreateUserWizard's validation by mitja.GTI? He's written several events and you can validate through it.

    And anyway, You can something like ValidationControls or js to validate.

    Thx

    Saturday, April 30, 2011 2:59 AM
  • User732704340 posted

    I've searched through his posts but found only one for CreateUserWizard validation and it has nothing to do with validating against a database, which is my main problem.

    Frown

    Saturday, April 30, 2011 4:32 AM
  • User3866881 posted

    Hi again:)

    Would you mind telling me what you mean by saying—— has nothing to do with validating against a database?

    I suggest you trying to use SqlCommand or SqlConnection with SqlDataReader to fetch specific data and do  with"if" statement to tell whether the fetched data is "valid" or not.

    Maybe you should show us some of your codes in details (part of finished codes)

    Thx

    Saturday, April 30, 2011 6:05 AM
  • User732704340 posted

    I meant that I'm completly new to this and if I don't see an example ,which shows exactly what I need to do, I won't be able to do it. I'm aware of SqlCommand, Connection and DataReader but I don't know how to use them correctly. And pleas don't send me to Microsoft library coz it requires to have some knowledge to use it. This is my aspx page code:

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <div id="regFrame">
            <asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
        OnActiveStepChanged="CreateUserWizard1_ActiveStepChanged" CssClass="createusrwiz" 
                Height="297px" Width="319px">
        <WizardSteps>
            <asp:TemplatedWizardStep ID="CustomStartStep1" runat="server" StepType="Start" 
                Title="CustomStartStep">
                <ContentTemplate>
                    <label id="patientID">Patient ID:</label>
                    <asp:TextBox ID="TextBox1" runat="server" CssClass="IDtxtbox"></asp:TextBox>
                </ContentTemplate>
            </asp:TemplatedWizardStep>
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
            </asp:CreateUserWizardStep>
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
            </asp:CompleteWizardStep>
        </WizardSteps>
    </asp:CreateUserWizard>
        </div>
        
    </asp:Content>

     

    and aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Register : System.Web.UI.Page
    {
        protected void CreateUserWizard1_ActiveStepChanged(object sender, EventArgs e)
        {
            if (CreateUserWizard1.ActiveStep.ID == "CreateUserWizardStep1")
            {
                
            }
        }
    }

    As I said before I need to validate input from the first step against two tables in database A (additional database). In table Patients in column PatiendID the number inputed by user must exist, whereas in the table PatientsOnline in column Online_Patients_ID the input must not exist. If this condition are met the wizard goes to the second step where a user provides his username, password, email and it all is saved in database B (default asp.net database). But also the ID provided by user in the first step must be passed to the second step and when user creates account the id is saved in database A in PatientsOnline table in Online_Patients_ID column.

    As you see it is quite complicated but I think necessrry to prevent users from registering multiple times.

    Saturday, April 30, 2011 6:34 AM
  • User-1828494216 posted

    Hi,

    as Decker Dong suggested you should look into SqlDataReader Class. At the end you have samples of C# and VisualBasic.

    protected void CreateUserWizard1_ActiveStepChanged(object sender, EventArgs e)
    {
        if (CreateUserWizard1.ActiveStep.ID == "CreateUserWizardStep1") //CreateUserWizard1.ActiveStepIndex = 1
        {
            string MyValidationString1;
            bool MyValidationString2;
            int MyValidationString3;
    
            string queryString =
            "SELECT OrderID, CustomerID FROM dbo.Orders;";
    
            using (SqlConnection connection =
                    new SqlConnection(connectionString))
            {
                SqlCommand command =
                    new SqlCommand(queryString, connection);
                connection.Open();
    
                SqlDataReader reader = command.ExecuteReader();
    
            // Call Read before accessing data.
                while (reader.Read())
                {
                    MyValidationString1 = reader[0].ToString();
                    MyValidationString2 = (bool)reader[1];
                    MyValidationString3 = (int)reader[2];
                }
    
            // Call Close when done reading.
            reader.Close();
            }
    
            // Now you validate...
    
            if(MyValidationString1 == "SomeString" && MyValidationString2 && MyValidationString3 == 1)
            {
                //let the user go to the next step
            }
            else
            {
                //Validation failed, set current active step to start step
                CreateUserWizard1.ActiveStepIndex = 0
            }
        }
    }
    NOTE: The code is not tested and not optimized, it's just a sample to get you going in the right direction ;)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 30, 2011 6:35 AM