Reputation: 19
I am trying to have an error message displayed when a username and password are not recognized.
if (rdr.Read())
{
int id = int.Parse(rdr.GetValue(0).ToString());
string fname = rdr.GetString(1);
Session["ID"] = id;
Session["FName"] = fname;
con.Close();
Response.Redirect("Home.aspx");
}
else
{
Response.Redirect("Login.aspx?err='blabla'"); //Display message
}
The following code (Page_Load) is supposed to be invoked in the else statement, but it is not:
public partial class _Default : System.Web.UI.Page
{
protected string err = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form.Count > 0)
{
err = Request.Form["err"];
}
}
}
Why is this the case? Thank you all so much!
Upvotes: 1
Views: 111
Reputation: 43077
This is a GET value in the query string, not a POST value in the form. You can use Request.QueryString[]
or Request[]
which contains POST and GET values.
if (Request.QueryString.Count > 0)
{
err = Request.QueryString["err"];
}
or
if (Request.Count > 0)
{
err = Request["err"];
}
Also, the query string value belongs to the Login page, so you won't be able to access it from _Default
. Move your Page_Load
logic to Login.aspx.cs.
Upvotes: 2
Reputation: 67898
Generally speaking, based off the class name _Default
, I believe you have placed this code in the Default.aspx
page. Place the code in the Load
for the Login.aspx
page. And then also follow the direction provided by jrummell.
Upvotes: 0