Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

accessing userid immediately after creating the user in asp.net

Posted on 2011-09-22
6
Medium Priority
?
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Expert Comment

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

Select SCOPE_IDENTITY()

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

0
 
LVL 15

Expert Comment

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

Accepted Solution

by:
guramrit earned 2000 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:

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:CPSRI
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 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
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.
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
ID: 36582773
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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