How to get username display after login screen?

Posted by Raghuldrag under ASP.NET on 6/24/2013 | Points: 10 | Views : 1363 | Status : [Member] | Replies : 4
Hai Friends,

I ve 2 aspx pages
1) Login.aspx
2)ermployeedetails.aspx

i ve already employee table like

locatn empname(employeecode along with name)
======= ========
chennai 0022:A
Banglore 0023:B
Hydrebad 0024:C

so i decided to make a username & password for all employees their employee code from the column of empname.
by using the sql query i splitted empname column as 'code' and 'name' separately.

now my requirement is when i was login in LOGIN.aspx page with the username of "A" emp code like '0022' and '0022' is password.
after the user login page ll be redirected to employee details page.
in that i need to display of the acutal empname fully.
i.e
if employee "A" is logined with his code '0022' and '0022'pwd.from Login Page.
ll go to employee details page
welcome "0022:A" like that.




Responses

Posted by: Satyapriyanayak on: 6/24/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down

Login.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_image_username_after_login
{
public partial class Login : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;

protected void btn_login_Click(object sender, EventArgs e)
{
object obj = null;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select count(*) from employee where UserName=@UserName and Password =@Password";
com = new SqlCommand(str, con);
com.CommandType = CommandType.Text;
Session["UserName"] = TextBox_user_name.Text;
com.Parameters.AddWithValue("@UserName", Session["UserName"]);
com.Parameters.AddWithValue("@Password", TextBox_password.Text);
obj = com.ExecuteScalar();
if ((int)(obj) != 0)
{
Response.Redirect("Welcome.aspx");
}
else
{
lb1.Text = "Invalid User name and Password";
clear();
}
con.Close();
}
private void clear()
{
TextBox_user_name.Text = "";
TextBox_password.Text = "";
}
}
}


Welcome.aspx.cs

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Display_image_username_after_login
{
public partial class Welcome : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlDataAdapter sqlda;
DataTable dt;

protected void Page_Load(object sender, EventArgs e)
{
lb1.Text = "<b><font color=Brown>" + "WELLCOME :: " + "</font>" + "<b><font color=red>" + Session["UserName"] + "</font>";
if (!IsPostBack)
{
bindgrid();
}
}

}
}


If this post helps you mark it as answer
Thanks

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 6/24/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Use Session in your page.


Thanks,
Bagesh Kumar Singh

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 6/26/2013 [Member] Starter | Points: 25

Up
0
Down
<asp:label id="lblname" Text=' <%= Session["UserName"] %>' runat="Server"/>

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 6/29/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
If this post helps you mark it as answer
Thanks

If this post helps you mark it as answer
Thanks

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response