Subscribe to Subscribers

Online Members

Farzin
More...

Forums » .NET » ASP.NET »

How can I display UserName instead of UserID from login page?


Posted Date: 29 Jul 2012      Posted By:: Moe     Member Level: Bronze    Member Rank: 1899     Points: 5   Responses: 5



Good day,

I have a page where the admin can add users with two text boxes
Enter userid
Enter Password

then it will be saved into a table called users

Then the user will open the login page and he will enter
his UserID and password, after logging in, there is a main page

I want to display his UserName when he opens the main page

what I did is to put this code in the main page:
Session["LoginUser"] = txtUserID.Text;

but the problem is that it's going to display the userID
How can I display UserName instead ?

Also, any idea of how can i display system date?




Responses

#682305    Author: Ravindran        Member Level: Diamond      Member Rank: 3     Date: 29/Jul/2012   Rating: 2 out of 52 out of 5     Points: 4

Moe,

During register add another one text box admin can add name too for that user.

After that in that login page code behind try like below to get user name


SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
SqlCommand sqlcmd;
SqlDataAdapter da;
DataTable dt = new DataTable();

//Login button click event
protected void Button1_Click(object sender, EventArgs e)
{
sqlcon.Open();
sqlcmd = new SqlCommand("select * from usr_detail where uid='" + txtUserID.Text + "' and pwd='" + txtpwd.Text + "'",sqlcon);
dt.Clear();
da = new SqlDataAdapter(sqlcmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Session["LoginUserId"] = txtUserID.Text;
//Set user name like this way
Session["LoginUserName"] = dt.Rows[0]["UserName"].ToString(); //change exact field name here as per in your table
Response.Redirect("Default2.aspx"); //Login success page
}
else {
TextBox1.Text = "";
TextBox2.Text = "";
Label1.Text = "Invalid Login Details!";
}
}


Regards
N.Ravindran
Your Hard work never fails


 
#682307    Author: girishsolanki      Member Level: Silver      Member Rank: 2484     Date: 29/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

Just Write HttpContext.Current.User.Identity.Name

For System Date
System.DateTime.Now


 
#682310    Author: Ajatshatru Upadhyay      Member Level: Gold      Member Rank: 17     Date: 29/Jul/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi,

As you are storing the user ID in the Session object, it is obvious that you only get the userID.
If you want to display user name, just fetch it from the database (I hope you are also storing user name in the database. So after successful login, just fetch the user name from the table and store it in Session object.

Let me know if you have any doubts.

Hope it'll help you.
Regards
Ajatshatru





 
#682312    Author: bulli guruvu setty      Member Level: Gold      Member Rank: 337     Date: 29/Jul/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi,

At the time of creating the user itself,it is better to store username as another field in data base table.

So that,we can retrieve the username from database and store in a session variable.

For getting only system date use below code:

System.DateTime.Now.ToShortDateString();


For getting only system time use below code:

System.DateTime.Now.ToShortTimeString();

Thanks & Regards
D.Bulli Guruvu Setty


 
#682389    Author: Moe      Member Level: Bronze      Member Rank: 1899     Date: 30/Jul/2012   Rating: 2 out of 52 out of 5     Points: 1

Thank You all you were very helpful

 
Post Reply
You must Sign In to post a response.

Next : Regarding Crystal Reports using views
Previous : Master page not working when i add gridview control
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.