Hi,
You have multiple option to do this.
Retrieve the user information in login page and pass that information through below technique.
1. Query String
2. Use session object
Update your code as below.
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select Firstname,Lastname from entry where Loginid = '" + txt_username.Text + " ' and Password = '" + txt_password.Text + "'",con);
SqlDataReader dr = cmd.ExecuteReader();
if(dr.HasRows)
{
dr.Read();
Session["FNAME"] = dr["Firstname"].ToString();
Session["FNAME"] = dr["Lastname"].ToString();
dr.Close();
con.Close();
Label3.Text = "Valid Login ID and Password";
Label3.ForeColor = System.Drawing.Color.DarkGreen;
Server.Transfer("default2.aspx");
}
else
{
Label3.Text = "Login ID Does Not Match";
Label3.ForeColor = System.Drawing.Color.DarkOrange;
}
}
Access Session value in default page2's page load or any other page.
Or
Pass first name and last name in query string.
dr.Read();
fName = dr["Firstname"].ToString();
lName = dr["Lastname"].ToString();
Server.Transfer("default2.aspx?FNAME="+fName+"&LNAME="+lName);
Or
Pass user ID to next page and retrieve user information from the DB in next page.
Hope this will help you.