• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

accessing userid immediately after creating the user in asp.net

I want to get the userid of the created user in the same page (infact create user page) immediately after creating the user. How can i do that? Please help me.
Thanks in advance
1 Solution
You need to check the insert procedure of creating user,

in Sql
after insert if your userid column is auto increment value then write after the insert statement


and in your Data Acess
use ExecuteNONQuery to retrieve the inserted(user Id)  value.

from the stored procedure you can return the user record after inserting to the table
use select f1,f2.f3 from users where id= SCOPE_IDENTITY()
There should be a CreateUserWizard control on page. Add handler to "OnCreatedUser" event, say "CreateUserWizard1_OnCreatedUser". CreateUserWizard1_OnCreatedUser event will be fired when user is created.
Now in this function you can access just created username using property CreateUserWizard1.UserName,
see following code:


<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnCreatedUser=CreateUserWizard1_OnCreatedUser>

code behind:
    protected void CreateUserWizard1_OnCreatedUser(object sender, EventArgs e)
        var uname = CreateUserWizard1.UserName;
        // do something...
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

CPSRIAuthor Commented:
hey, i am so excited to meet you both again here, thanks for your replies but i want to access it in my asp.net page using c# code, and i am using asp.net membership class to create user. i can get the solution if you tell me exactly which stored procedure will be used to create user, in my case, using Membership class.
If you are using Membership class, then you'll be using Membership.CreateUser to create user.
This function returns MembershipUser, which contains all the properties of newly created user.

MembershipUser user = Membership.CreateUser("testuser", "testpassword");
lblUser.Text = "Hello " + user.UserName;

CPSRIAuthor Commented:
Thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now