accessing userid immediately after creating the user in

Posted on 2011-09-22
Last Modified: 2012-05-12
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
Question by:CPSRI

Expert Comment

ID: 36579820
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.

LVL 15

Expert Comment

ID: 36579831
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()

Accepted Solution

guramrit earned 500 total points
ID: 36579865
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...
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Comment

ID: 36579875
hey, i am so excited to meet you both again here, thanks for your replies but i want to access it in my page using c# code, and i am using 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.

Expert Comment

ID: 36582014
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;

Author Closing Comment

ID: 36582773
Thank you

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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