I attempt to save the selection of a dropdown to a cookie in the SelectedIndexChanged event.
protected void BranchNumberList_SelectedIndexchanged(object sender, EventArgs e)
{
HttpCookie myCookie = new HttpCookie("default_Loc", BranchNumberList.SelectedValue);
myCookie.Expires = DateTime.Now.AddDays(365);
Response.Cookies.Add(myCookie);
ViewDate.Enabled = true;
SelectEverything();
}
myCookie looks fine and I can see it in the response object with a quickwatch.
I try to retrieve it on the next login when this method is called from Page_Load.
private void BranchName()
{
DatabaseHelpers dh = new DatabaseHelpers();
DataSet DrpDownSrc = dh.FillBranchSelection(objConn);
BranchNumberList.DataSource = DrpDownSrc;
BranchNumberList.DataTextField = "BranchName";
BranchNumberList.DataValueField = "LocationID";
BranchNumberList.DataBind();
BranchNumberList.Items.Insert(0, "Select a branch");
try
{
BranchNumberList.SelectedValue = this.Request.Cookies["default_Loc"].Value;
}
catch (Exception)
{
BranchNumberList.SelectedIndex = 0;
}
}
I always get 'this.Request.Cookies["default_Loc"]' is null.
Can anyone see where I am going wrong?