Solved

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

Posted on 2008-09-29
8
752 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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