Solved

How do I store username in asp.net CreatUserwizard in session variable?

Posted on 2008-09-29
8
742 Views
Last Modified: 2013-12-17
I want to store the username in a session and retrieve it later.  How would i do this? Or does the wizard store this value, and if so how to i retrieve from the wizard?

Thanks for any help.

Code I have:
Session[UserName] = UserName.Text;  // this does not work
0
Comment
Question by:bmanmike39
  • 3
  • 3
8 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22602041
replace it to
Session["UserName"] = UserName.Text;  

this line will come only once your user has been authenticated
0
 

Author Comment

by:bmanmike39
ID: 22602058
I get the error " UserName does not exist in the current context"
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22602077
can you please share your asp.net code and the code behind code so that we can understand the actual problem and suggest you an asnwer
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:bmanmike39
ID: 22602094
This is my code:
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 

    FinishDestinationPageUrl="~/mgrConsol.aspx" 

        oncreateduser="CreateUserWizard1_CreatedUser" ActiveStepIndex="1" 

        oncreatinguser="CreateUserWizard1_CreatingUser" Width="341px">

        <HeaderTemplate>

            Enter a New Application Name

        </HeaderTemplate>

    <WizardSteps>

        <asp:WizardStep runat="server" StepType="Start" 

            Title="Enter a New Application Name">

            <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" 

                Width="163px"></asp:TextBox>

            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 

                ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>

        </asp:WizardStep>

        <asp:CreateUserWizardStep runat="server" >

            <ContentTemplate>

                <table border="0" style="font-size:100%;width:341px;">

                    <tr>

                        <td align="center" colspan="2">

                            Sign Up for Your New Account</td>

                    </tr>

                    <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="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="QuestionLabel" runat="server" AssociatedControlID="Question">Security 

                            Question:</asp:Label>

                        </td>

                        <td>

                            <asp:TextBox ID="Question" runat="server"></asp:TextBox>

                            <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" 

                                ControlToValidate="Question" ErrorMessage="Security question is required." 

                                ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

                        </td>

                    </tr>

                    <tr>

                        <td align="right">

                            <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security 

                            Answer:</asp:Label>

                        </td>

                        <td>

                            <asp:TextBox ID="Answer" runat="server"></asp:TextBox>

                            <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" 

                                ControlToValidate="Answer" ErrorMessage="Security answer is required." 

                                ToolTip="Security answer 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 runat="server" >

            <ContentTemplate>

                <table border="0" style="font-size:100%;width:341px;">

                    <tr>

                        <td align="center" colspan="2">

                            Account Created Successfully</td>

                    </tr>

                    <tr>

                        <td>

                            Now you must create account profile.</td>

                    </tr>

                    <tr>

                        <td align="right" colspan="2">

                            <asp:Button ID="ContinueButton" runat="server" CausesValidation="False" 

                                CommandName="Continue" PostBackUrl="~/icsAdmin/CreateProfile.aspx" 

                                Text="Create Profile" ValidationGroup="CreateUserWizard1" />

                        </td>

                    </tr>

                </table>

            </ContentTemplate>

        </asp:CompleteWizardStep>

    </WizardSteps>

</asp:CreateUserWizard>
 
 

=============================  Code behind  =======================
 

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;
 
 

public partial class icsAdmin_createUser : System.Web.UI.Page

{

    string aID = "";

    protected void Page_Load(object sender, EventArgs e)

    {

        aID = TextBox1.Text;
 

        

       // Session["UserName"] = UserNameText;

     

        

    }

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)

    {

       //Roles.AddUserToRole(CreateUserWizard1.UserName, "icsAdmin");

       

    }

    

    

}

Open in new window

0
 

Author Comment

by:bmanmike39
ID: 22602105
oops!
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" 

    FinishDestinationPageUrl="~/mgrConsol.aspx" 

        oncreateduser="CreateUserWizard1_CreatedUser" ActiveStepIndex="1" 

        oncreatinguser="CreateUserWizard1_CreatingUser" Width="341px">

        <HeaderTemplate>

            Enter a New Application Name

        </HeaderTemplate>

    <WizardSteps>

        <asp:WizardStep runat="server" StepType="Start" 

            Title="Enter a New Application Name">

            <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged" 

                Width="163px"></asp:TextBox>

            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 

                ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>

        </asp:WizardStep>

        <asp:CreateUserWizardStep runat="server" >

            <ContentTemplate>

                <table border="0" style="font-size:100%;width:341px;">

                    <tr>

                        <td align="center" colspan="2">

                            Sign Up for Your New Account</td>

                    </tr>

                    <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="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="QuestionLabel" runat="server" AssociatedControlID="Question">Security 

                            Question:</asp:Label>

                        </td>

                        <td>

                            <asp:TextBox ID="Question" runat="server"></asp:TextBox>

                            <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" 

                                ControlToValidate="Question" ErrorMessage="Security question is required." 

                                ToolTip="Security question is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>

                        </td>

                    </tr>

                    <tr>

                        <td align="right">

                            <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security 

                            Answer:</asp:Label>

                        </td>

                        <td>

                            <asp:TextBox ID="Answer" runat="server"></asp:TextBox>

                            <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" 

                                ControlToValidate="Answer" ErrorMessage="Security answer is required." 

                                ToolTip="Security answer 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 runat="server" >

            <ContentTemplate>

                <table border="0" style="font-size:100%;width:341px;">

                    <tr>

                        <td align="center" colspan="2">

                            Account Created Successfully</td>

                    </tr>

                    <tr>

                        <td>

                            Now you must create account profile.</td>

                    </tr>

                    <tr>

                        <td align="right" colspan="2">

                            <asp:Button ID="ContinueButton" runat="server" CausesValidation="False" 

                                CommandName="Continue" PostBackUrl="~/icsAdmin/CreateProfile.aspx" 

                                Text="Create Profile" ValidationGroup="CreateUserWizard1" />

                        </td>

                    </tr>

                </table>

            </ContentTemplate>

        </asp:CompleteWizardStep>

    </WizardSteps>

</asp:CreateUserWizard>
 
 

=============================  Code behind  =======================
 

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;
 
 

public partial class icsAdmin_createUser : System.Web.UI.Page

{

  

    protected void Page_Load(object sender, EventArgs e)

    {

       
 

        

        Session["UserName"] = UserNameText;

     

        

    }

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)

    {

       //Roles.AddUserToRole(CreateUserWizard1.UserName, "icsAdmin");

       

    }

    

    

}

Open in new window

0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 22602143
the values from the createuserwizard cannot be retrieved directly as we have been trying to do

to fetch username we will have to use
Session["UserName"] = ((TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName")).Text

please have a look at the sample from the MSDN site might be more helpful than i can be
http://msdn.microsoft.com/en-us/library/ms178342(VS.80).aspx
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now