G
Groove
Hey guys - hoping you can help me out here. I'm using asp.net 2 (VB) and
trying to set and retrieve values from a cookie. I've done this a few times
before w/o a problem but I seem to be overlooking something here. I'm even
following my previous working examples and I can't see the different.
I have a page that will remember the user's settings using a cookie. Ther
Calendar Events, recent orders, etc will be displayed or hidden based upon
the checkboxes they select (but I haven't gotten that far yet). I'm getting
an error at:
Object reference not set to an instance of an object.
strMyEvents = objCookie.Values("MyEvents")
After using the code below, I tried to search the PC for a cookie and
couldn't find it which makes me think it doesn't exist. Yet, when I
response.redirect the value of the cookie just to test, it indeed finds
"True"
Any ideas??
Here's a simplified version of my code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Page.IsPostBack = False Then
Dim objCookie As HttpCookie
Dim strMyEvents As String
objCookie = Page.Request.Cookies("Intranet")
If IsNothing(objCookie) = True Then
SetCookie("True")
End If
strMyEvents = objCookie.Values("MyEvents")
lblTest.Text = strMyEvents
End If
End Sub
Protected Sub SetCookie(ByVal strMyEvents As String)
Dim objCookie As HttpCookie
objCookie = New HttpCookie("Intranet")
objCookie.Expires = DateTime.MaxValue
objCookie.Values("MyEvents") = "True"
'Response.Redirect(objCookie.Values("MyEvents"))
End Sub
trying to set and retrieve values from a cookie. I've done this a few times
before w/o a problem but I seem to be overlooking something here. I'm even
following my previous working examples and I can't see the different.
I have a page that will remember the user's settings using a cookie. Ther
Calendar Events, recent orders, etc will be displayed or hidden based upon
the checkboxes they select (but I haven't gotten that far yet). I'm getting
an error at:
Object reference not set to an instance of an object.
strMyEvents = objCookie.Values("MyEvents")
After using the code below, I tried to search the PC for a cookie and
couldn't find it which makes me think it doesn't exist. Yet, when I
response.redirect the value of the cookie just to test, it indeed finds
"True"
Any ideas??
Here's a simplified version of my code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Page.IsPostBack = False Then
Dim objCookie As HttpCookie
Dim strMyEvents As String
objCookie = Page.Request.Cookies("Intranet")
If IsNothing(objCookie) = True Then
SetCookie("True")
End If
strMyEvents = objCookie.Values("MyEvents")
lblTest.Text = strMyEvents
End If
End Sub
Protected Sub SetCookie(ByVal strMyEvents As String)
Dim objCookie As HttpCookie
objCookie = New HttpCookie("Intranet")
objCookie.Expires = DateTime.MaxValue
objCookie.Values("MyEvents") = "True"
'Response.Redirect(objCookie.Values("MyEvents"))
End Sub