You can try this:
Step 1: Suppose you have button and on button click you are redirecting the users. So
before redirection, take the username and store it in the session. Something like this:
protected void Button1_Click(object sender, EventArgs e) {
SqlConnection con = new SqlConnection(@YourConnectionString");
SqlCommand cmd = new SqlCommand("select * from tbl_data where username=@username and word=@word", con); // use Stored Procedure to avoid SQL injection hacks
cmd.Parameters.AddWithValue("@username", TextBox1.Text);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (dt.Rows.Count > 0) {
Session["username"] = TextBox1.Text; // store the value of username in Session
Response.Redirect("Redirectform.aspx");
} else {
// something else
}
}
Your LayoutPage:
In this Layout Page, go to the PageLoad event in c# (backend)
protected void Page_Load(object sender, EventArgs e)
{
lblUserName.Text = Session["username].ToString();
}
Note: The C# code for Login is just a demo. Use your own code.