0

how to retrive username and other information after succefully login using loginid and passs

like

in login screen (user will use his/her)

Userid:xyz
Password:xxx

in home page

i want to dispaly his/her name !!!!

urgent help!!!!!!!!!!!!

Edited by gangaloves7: didn't added the tags

7
Contributors
16
Replies
17
Views
7 Years
Discussion Span
Last Post by samkaraja
0

you can use the "User" property of page.
for example, "string strUserId = User.Identity;
UserLabel.Text = strUserId;"
If you don't understand well, you can ask me in detail using MSN
Good luck~

0

first, user login in.
Next, user id is stored in the property of page called "User"(Page.User)
You can get user id using this scritp;
string userId = User.Identity;
you can display this userId~~
That's enough?

0

i want to display user name which is in database table noy the id which is used to login..................

1

Why are you not using Session variable ? At the time of UserLogin, when User credential match/success, Just store the User Related information in Session variable and use this session variable in any page within your application.

Session["UserName"] = "Test";
Label1.Text = Session["UserName"].ToString();

Try by this !!

i want to display user name which is in database table noy the id which is used to login..................

0

ya i know tht but i want to display something like this

in my database table i have three columns

Userid: stu1
Password: stu1
StudentName: XYZ

i want to display username in welcome screen not the id which i use to login

0

So what the problem is ?
Yet you can show the StudentName as UserName in Welcome screen with the help of Session. You can do it like below code..

SqlDataAdapter objAdpt = new SqlDataAdapter("Select * from yourtable Where UserID='User Entered' And Password ='User Entered'", your connection);
DataTable objDt = new DataTable ();
objAdpt.Fill(objDt);
if(objDt.Rows.Count > 0)
{
    Session["UserName"] = objDt[0]["StudentName"].ToString();
}

Now on Welcome screen Lable, just retrieve value from Session like below :
Label1.Text = Session["UserName"].ToString();

that's all...
try by this and let us know If you stil have any confusion..

ya i know tht but i want to display something like this

in my database table i have three columns

Userid: stu1
Password: stu1
StudentName: XYZ

i want to display username in welcome screen not the id which i use to login

0

In the login page in case of successful login write the following code
Session["userid"] = t1.Text;
Now you have session variable in all your website pages called userid
In the second page write code like this
String userid = Session["userid"].ToString();
sqlDataAdapter d=new sqlDataAdapter("select studentname from students where userid="+userid,connstring);
Label1.text=....... studentname which retrieve from the previous statement

thanks

0

mohammed yaghi - UserID and UserName is different. Why are you storing UserID in Session and then again storing value of session in String variable and executing the query to retrieve only UserName in case of Successful login.
try to minimize the code always. The reason is in large application this type of things makes delay to run application..

In the login page in case of successful login write the following code
Session["userid"] = t1.Text;
Now you have session variable in all your website pages called userid
In the second page write code like this
String userid = Session["userid"].ToString();
sqlDataAdapter d=new sqlDataAdapter("select studentname from students where userid="+userid,connstring);
Label1.text=....... studentname which retrieve from the previous statement

thanks

0

rohand The solution required to login by userid and then retrieve name from query
Dear I assigned session to string just for explaining and details explian just
I Know that I can do it without storing in variable
thanks for advice

0

hi rohand its showing errorr

cannot apply indexing with [] to an expression of type 'System.Date.DataTable'

0

why session..

use shortcut..

after successful credential match

{
 FormsAuthentication.SetAuthCookie(txtUserName.Text,false);
 Response.Redirect("NextPage.aspx");
}

on NextPage.aspx add a Label

on FormLoad Event
{
if(Request.IsAuthenticated)
 Label1.Text = User.Identity.Name;
else
 // Redirect to Login Page
}

// Done and Hope that helps

0

thanks for help ... but i used another method to get user name...
thanks to u all!!!!

0

step 1:

create a session of your text storing like this. this line is appear at your ok(login) button last line.

session["your name"]=username.text

step 2:

create a lable box at any one of the corner of your form without text property.

then write the code for in your form load action

label1.text=session["yourname"].text


Try this and send the result to my mail

My mail id samkaraja@gmail.com

With regards

Rajapandian

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.