So i made 2 pages, one for settings and one for label and images. the thing that i want is when there is no cookies the img_gm.BorderWidth and img_gm.Bordercolor will be 1 and Black by default, but it seems error always occur in libe "img_gm.BorderWidth = Convert.ToInt32(cookie["width"]);" any help will be appreciated.
*i put text box, dropdown list and radio button in settings page to get an input of cookies["width"], cookies["color"] and cookies["font"]
protected void Page_Load(object sender, EventArgs e) {
HttpCookie cookie = Request.Cookies["settings"];
if (Request.Cookies.AllKeys.Contains("settings") == null)
{
cookie["width"] = "1";
cookie["color"] = "Black";
cookie.Expires = DateTime.Now.AddDays(14);
Response.Cookies.Add(cookie);
}
else
{
img_gm.BorderWidth = Convert.ToInt32(cookie["width"]);
img_gm.BorderColor = System.Drawing.Color.FromName(cookie["color"]);
switch (cookie["font"])
{
case "Bold":
lbl_desc.Font.Bold = true;
break;
case "Italic":
lbl_desc.Font.Italic = true;
break;
case "Overline":
lbl_desc.Font.Overline = true;
break;
case "Underline":
lbl_desc.Font.Underline = true;
break;
}
}
Response.Cookes.AllKeys
in your if block? Maybe it should beRequest
? – Sergey Litvinovcookie["width"]
value what value does it have? maybe it has some old testing value that isn't integer, so it fails during parsing? and cookie just needs to be cleared in the browseR? – Sergey Litvinov