Follow my previous help in stackoverflow on discussion: Show a div in asp.net on condition
I have an ASP.NET page wiich include a webform in HTML has javascript code set cookie. (I know the javascript is setting the cookies because I can see them in google chrome with the combination of ctrl+shift+I ).
I wrote in the code behind this solution in order to show/not show the form based on the value cooke set or not:
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie myCookie = new HttpCookie("tempcookieforclose");
myCookie = Request.Cookies["tempcookieforclose"];
// Read the cookie information and display it.
if (myCookie != null)
webform.Visible = false;
else
webform.Visible = true;
That does not work. As well is not working this exemple that show if cookie name are set in the output:
HttpCookie myCookie = new HttpCookie("MyTestCookie");
myCookie = Request.Cookies["MyTestCookie"];
// Read the cookie information and display it.
if (myCookie != null)
Response.Write("<p>"+ myCookie.Name + "<p>"+ myCookie.Value);
else
Response.Write("not found");
(I changed MyTestCookie with the name of "mycookie")
as well I post the function the sets cookie for my webform:
function tempcookie() {
days = 1; // number of days to keep the cookie
myDate = new Date();
myDate.setTime(myDate.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = 'cookieName=cookieclose; expires=' + myDate.toGMTString();
function permacookie() {
days = 30; // number of days to keep the cookie
myDate = new Date();
myDate.setTime(myDate.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = 'cookieName=cookiesignup; expires=' + myDate.toGMTString();
}