Hi!
I putted a "label" on my next page that I want to mention the real username after log in
Then this username should appear on the next page ONLY when the username and password are correct
How can I do it? this my codes:
protected void log_Click(object sender, EventArgs e)
{
SqlDataSource sds = new SqlDataSource();
sds.ConnectionString = ConfigurationManager.ConnectionStrings["master"].ToString(); sds.SelectParameters.Add("username", TypeCode.String, this.username.Text);
sds.SelectParameters.Add("password", TypeCode.String, this.password.Text);
sds.SelectCommand = "SELECT * FROM [myTb] WHERE [username] = @username AND [password] = @password";
DataView dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);
try
{
if (dv.Count == 0)
{
this.lblinfo.ForeColor = System.Drawing.Color.Red;
this.lblinfo.Text = "Invalid username and password!";
return;
}
else
{
FormsAuthentication.RedirectFromLoginPage(username.Text, true);
Response.Redirect("~/English/Visual.aspx");
//It's here where I need the codes
}
}
catch
{
}
finally
{
}
}
}
Loading
IsraelPosted Jan 27, 2014, 6:44 AM
IsraelPosted Jan 24, 2014, 12:15 PM
Session["UserName"] = username.Text; //the bug it's here
// This one dont work. Its give me the same word username
Session["UserName"] = "username.Text";
on next page (Visual.aspx) onload event
lblinfo.Text = convert.Tostring(Session["UserName"]);
Jignesh TrivediPosted Jan 23, 2014, 7:23 AM
hi,
In this case you can put you user name in to the session and next page load you can use this session Data.
example
Session["UserName"] = "Jignesh"
on next page (Visual.aspx) onload event
lbl1.Text = convert.Tostring(Session["UserName"]);
hope this will help you.