On the load of a certain .aspx web page I check to see if a cookie exists with an email address inside (in other words they have used this page before and an email address was entered). If it exists, it is automatically put into a textbox on the form. However this only works once and as soon as the textbox is populated the email address is gone from the cookie. Almost like it was cut out of the cookie and not copied so the next time I use the cookie the email address isnt there anymore. Here is the code:
If I step through this code it always goes through the else branch and when its completed and the web page appears I look into the cookie and the value is gone. Thanks for at least looking. Anyone?
Code:
Private Sub Page_Load(...)
If Request.Browser.Cookies then
If Request.Cookies("email") is Nothing then
Dim cookEmail As New HttpCookie("email", "")
cookEmail.Expires = DateTime.Now.AddDays(14)
Response.Cookies.Add(cookEmail)
Else
Dim cookEmail as HttpCookie = Request.Cookies("email")
If Me.TextBox1.Text = "" Then Me.TextBox1.text = cookEmail.Value
Response.Cookies("email").Expires = DateTime.Now.AddDays(14)
Endif
Endif
End Sub
If I step through this code it always goes through the else branch and when its completed and the web page appears I look into the cookie and the value is gone. Thanks for at least looking. Anyone?