I've added bits of debug code in an attempt to figure out what is going on with my Session variable, and it appears that it is always empty.
Could someone tell me what I am doing wrong?
This is probably some noobie mistake, because I don't do much web development.
private const string PASSWORD = "PASSWORD";
protected void Page_Load(object sender, EventArgs e) {
if (String.IsNullOrEmpty(password)) {
lblMessage.Text = !IsPostBack ? "Not a PostBack!" : "A PostBack.";
} else {
ShowData(IsPostBack);
}
}
private string password {
get { return Session[PASSWORD] as string; }
set { Session[PASSWORD] = value; }
}
protected void Password_Click(object sender, EventArgs e) {
string val = txtPassword.Text.Trim();
if (val == ConfigurationManager.ConnectionStrings[PASSWORD].ConnectionString) {
password = val;
txtPassword.Text = null;
} else {
Response.Redirect(val);
}
}
private void ShowData(bool postType) {
// I would display my data here if it ever got to this point!
}
EDIT: When the Password_Click event fires, all I ever see is "Not a PostBack!" or "A PostBack." So, my Session variable must not be getting set.
Password_Clickdoesn't get called. Can you put a breakpoint there and see whether the variable actually gets set. If not show us the ASP.NET markup so we can see why it's not firing the event