So if you trying to display information about a student on a page after login, your student info UI page is going to need to know who is logged in for the current asp.net session that is executing. The are few ways to do this such as forms authentication, and it depends on what mechanism you are using to track logged in sessions. Looking at your code it does not appear that you are using anything to track user and session logons, so I will focus on what you are asking and that is display the student info on a page after login.
below is pure example and should not be used in a production env
Code:
public partial class Login : System.Web.UI.Page
{
private string m_ConnectionString = "some sql con string";
private string m_AuthenticateCmd = "Select count(*) from user_login where username = :p_UserId and password = :p_Password";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login_Click(object sender, EventArgs e)
{
if (IsValid)
{
if (Authenticated(TextBox1.Text, TextBox2.Text))
{
// passing userid to student home via session variable
// could have dont any number of ways but i chose this for simplicty
Session["User"] = TextBox1.Text;
Response.Redirect("StudentHome.aspx");
}
}
}
/// <summary>
/// Authenticates a user id and password combination
/// </summary>
/// <param name="userid"></param>
/// <param name="pwd"></param>
/// <returns></returns>
private bool Authenticated(string userid, string pwd)
{
var rVal = false;
using (var con = new SqlConnection(m_ConnectionString))
{
using (var cmd = new SqlCommand(m_AuthenticateCmd, con))
{
// use commnad parameters to gaurd against sql injection
cmd.Parameters.Add("p_userId", System.Data.SqlDbType.VarChar).Value = userid;
cmd.Parameters.Add("p_Password", System.Data.SqlDbType.VarChar).Value = pwd;
rVal = ((int)cmd.ExecuteScalar()) == 1;
}
}
return rVal;
}
}
public partial class StudentHome : System.Web.UI.Page
{
private string m_ConnectionString = "some sql con string";
private string m_SelectUserCmd = "Select * from user_login where username = :p_UserId";
protected void Page_Load(object sender, EventArgs e)
{
var userId = Session["User"] as string;
if (String.IsNullOrEmpty(userId))
{
if (!IsPostBack)
{
using (var con = new SqlConnection(m_ConnectionString))
{
using (var cmd = new SqlCommand(m_SelectUserCmd, con))
{
// use commnad parameters to gaurd against sql injection
cmd.Parameters.Add("p_userId", System.Data.SqlDbType.VarChar).Value = userId;
using (var reader = cmd.ExecuteReader())
{
if (reader.Read())
{
TextBox1.Text = reader["name"].ToString();
TextBox2.Text = reader["dob"].ToString();
TextBox3.Text = reader["class"].ToString();
TextBox4.Text = reader["department"].ToString();
TextBox5.Text = reader["contact"].ToString();
}
}
}
}
}
}
}
}
so from the above we can see that the StudentHome page now has access to who is logged in for the current asp.net session. Of course this purely example and some other mechanism should be used to tie a user to a session. Check out forms authentication.