Solved

accessing userid immediately after creating the user in asp.net

Posted on 2011-09-22
6
272 Views
Last Modified: 2012-05-12
Hi,
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
0
Comment
Question by:CPSRI
6 Comments
 
LVL 6

Expert Comment

by:kswathi
Comment Utility
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

Select SCOPE_IDENTITY()

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

0
 
LVL 15

Expert Comment

by:Eyal
Comment Utility
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()
0
 
LVL 4

Accepted Solution

by:
guramrit earned 500 total points
Comment Utility
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:

aspx:

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


code behind:
    protected void CreateUserWizard1_OnCreatedUser(object sender, EventArgs e)
    {
        var uname = CreateUserWizard1.UserName;
        // do something...
       ...
       ...
       ...
    }
0
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

 

Author Comment

by:CPSRI
Comment Utility
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.
0
 
LVL 4

Expert Comment

by:guramrit
Comment Utility
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.
e.g.

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

http://msdn.microsoft.com/en-us/library/d8t4h2es.aspx
0
 

Author Closing Comment

by:CPSRI
Comment Utility
Thank you
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

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…
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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

9 Experts available now in Live!

Get 1:1 Help Now