Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am a new ASP.NET developer and I am developing the first web application to me with this programming language. I am trying to use the Wizard Control for managing the user by developing the following scenario:

**Wizard Step1:** contains a TextBox where the admin can put the username of the user
and when he clicks on the next button the username will be checked a against the users table in the database; if he is existed in the database, his information will be shown in the Wizard Step2 and his information will be read-only. If he is not existed, the admin will be notified with a message.

**Wizard Step2:** contains a Repeater or Placeholder that shows the user information.

**Wizard Step3:** Also, if the user existed this step will show the current role of this user in the system with showing a button for editing the role of him


My ASP.NET code:

ASP.NET
<asp:Wizard ID="Wizard1" runat="server" DisplaySideBar="false" Width="80%" >
            <wizardsteps>
                <asp:WizardStep ID="WizardStep1" runat="server" title="Employee Username/Network ID">
                    <table border="0">
                        <tr>
                            <td class="InputLabel">Username:</td>
                            <td class="InputControl">
                                <asp:TextBox ID="TextBox1" runat="server" />
                            </td>
                        </tr>
                    </table>

                <asp:WizardStep ID="WizardStep2" runat="server" title="Manage User">
                    <div class="content">
                        <asp:Repeater ID="Repeater1" runat="server">
                            <itemtemplate>

                            </itemtemplate>

                    </div>

                <asp:WizardStep ID="WizardStep3" runat="server" Title="Edit User Role">
                    <label for="role">Current Role: </label>
                    <asp:Label ID="Label1" runat="server" BackColor="#FFFF99" Font-Bold="True" ForeColor="#000099" />
                    <asp:RadioButtonList id="radio1" runat="server" TextAlign="left">
                        <asp:ListItem id="option1" runat="server" value="Admin" />
                        <asp:ListItem id="option2" runat="server" value="Contribute" />
                        <asp:ListItem id="option3" runat="server" value="User" />

                    <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Clicked" />

            </wizardsteps>

            <HeaderTemplate>
               <ul id="wizHeader">
                   <asp:Repeater ID="SideBarList" runat="server">
                       <itemtemplate>
                           <li><a class="<%# GetClassForWizardStep(Container.DataItem) %>" title="<%#Eval(" name=")%>">
                               <%# Eval("Name")%></a> </li>
                       </itemtemplate>

               </ul>
           </HeaderTemplate>




And the Code-Behind is

C#
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserManagement : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

        string username = TextBox1.Text;

        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdb;Integrated Security=True";
        string cmdText = "SELECT * FROM employee WHERE Username = @Username";

        //For checking the user
        if (username != null)
        {
            if (CheckUsername(username) == true)
            {
                try
                {
                    SqlConnection conn = new SqlConnection(connString);
                    conn.Open();
                    SqlDataReader myReader = null;
                    SqlCommand myCommand = new SqlCommand(cmdText, conn);
                    myReader = myCommand.ExecuteReader();
                    while (myReader.Read())
                    {
                        Console.WriteLine(myReader["Name"].ToString());
                        Console.WriteLine(myReader["JobTitle"].ToString());
                        Repeater1.DataSource = myReader;
                        Repeater1.DataBind();
                        myReader.Close();
                        conn.Close();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }

        //For sending object to the Wizard1.PreRender
        Wizard1.PreRender += new EventHandler(Wizard1_PreRender);

    }


    //Method for checking the existence of the username in the database (retrun true or false)
    private bool CheckUsername(string username)
    {
        string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdb;Integrated Security=True";
        string cmdText = "SELECT Count(*) FROM employee WHERE Username = '" + username + "'";

        using (SqlConnection conn = new SqlConnection(connString))
        {
            conn.Open(); // Open DB connection.

            using (SqlCommand cmd = new SqlCommand(cmdText, conn))
            {
                int count = (int)cmd.ExecuteScalar();
                // True (> 0) when the username exists, false (= 0) when the username does not exist.
                return (count > 0);
            }
        }

    }


    protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        if (Wizard1.ActiveStepIndex == 1)
        {
            string username = TextBox1.Text;
        }
    }


    //Method for replacing the default sidebar of the Wizard Control with a custom sidebar (represented in a repeater)
    protected void Wizard1_PreRender(object sender, EventArgs e)
    {
        Repeater SideBarList = Wizard1.FindControl("HeaderContainer").FindControl("SideBarList") as Repeater;
        SideBarList.DataSource = Wizard1.WizardSteps;
        SideBarList.DataBind();
    }

    protected string GetClassForWizardStep(object wizardStep)
    {
        WizardStep step = wizardStep as WizardStep;

        if (step == null)
        {
            return "";
        }
        int stepIndex = Wizard1.WizardSteps.IndexOf(step);

        if (stepIndex < Wizard1.ActiveStepIndex)
        {
            return "prevStep";
        }
        else if (stepIndex > Wizard1.ActiveStepIndex)
        {
            return "nextStep";
        }
        else
        {
            return "currentStep";
        }
    }


    protected void Button1_Clicked(Object sender, EventArgs e)
    {
        // When the button is clicked,
        // show the new role of the user
        //Label1.Text = "...button clicked...";

    }



}



        //Session["Username"] = Username.Text;
        //String strUserName = Request.QueryString["Username"];

        //string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=psspdb;Integrated Security=True";
        //string cmdText = "SELECT * FROM employee WHERE Username = @Username";

        ////For checking the user
        //if (Request.QueryString["Username"] != null)
        //{
        //    //String strUserName = Request.QueryString["Username"];

        //    ////Check userName Here
        //    //String strReturnStatus = "false";

        //    if (CheckUsername(Request.QueryString["Username"]) == true)
        //    {
        //        //strReturnStatus = "true";
        //        try
        //        {
        //            SqlConnection conn = new SqlConnection(connString);
        //            conn.Open();
        //            SqlDataReader myReader = null;
        //            SqlCommand myCommand = new SqlCommand(cmdText, conn);
        //            myReader = myCommand.ExecuteReader();
        //            while (myReader.Read())
        //            {
        //                Console.WriteLine(myReader["Name"].ToString());
        //                Console.WriteLine(myReader["JobTitle"].ToString());
        //                Repeater1.DataSource = myReader;
        //                Repeater1.DataBind();
        //                myReader.Close();
        //                conn.Close();
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            Console.WriteLine(ex.ToString());
        //        }
        //    }

I am struggling with the code-behind a lot. It did not work even for checking the username and I don't know why. Also, I am not sure if I should put any piece of code inside <asp:Repeater> or not for showing the user information from the database.
Posted
Updated 3-Dec-11 1:43am
v2
Comments
Richard MacCutchan 3-Dec-11 7:43am    
Added <pre> tags for readability.

You can a try a completely different approach for your problem as discussed in the below articles:
JavaScript Create User Wizard for ASP.NET[^]
 
Share this answer
 
Hi Matrix,

Where is the end tag for repeater ?

Where you have placed anything like label to bind data in repeater ?

Please check the basic kind of binding repeater in google.
 
Share this answer
 
Comments
matrix388 3-Dec-11 13:41pm    
I think I do it in the Page_Load method. Please check it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900