response.cookies problem

yaniv

Centurion
Joined
Apr 15, 2002
Messages
167
Location
israel
I"m trying to read a cookie from the clinet machine using the code:

If not Request.Cookies("shoresh")("newmasinblogs") is nothing Then
If Request.Cookies("shoresh")("newmasinblogs") = "כן" Then
massagenum.Text = dataset.Tables("massages").Rows.Count
CheckBox1.Checked = True
End If
End If

the problem is that i get error massege:
"Object reference not set to an instance of an object."

i just can't solve the problem,

i tried to rewrite the cookies, i tried to set it to nothing and then to rewrite it... nothing working.

do somebody knows what the problem is?
 
Try changing the first line to the following:

Code:
If Not Request.Cookies("shoresh") Is Nothing AndAlso Request.Cookies("shoresh")("newmasinblogs") Is Nothing Then

Not sure if this helps.
 
Does the dataset and the Table "massages" exist? IF so what is the value of dataset.Tables("massages").Rows.Count if you step through the code in the debugger?
 
it is more then 0,

it's 3 or 4.

i get the error massage even in the first checking of the cookies... (if request.cookies... is nothing....)
 
may be when i set the cookies to nothing i caused a problem?

i tried to import "server.web.httpcookies",

it is just not working!!!
 
How about if you did
Visual Basic:
If (not Request.Cookies("shoresh") is nothing) andalso (not Request.Cookies("shoresh")("newmasinblogs") is nothing) Then
    If Request.Cookies("shoresh")("newmasinblogs") = "כן" Then
        massagenum.Text = dataset.Tables("massages").Rows.Count
        CheckBox1.Checked = True
    End If
End If
 
in your original code
Code:
 If not Request.Cookies("shoresh")("newmasinblogs") is nothing
it will try to evaluate Cookies("shoresh")("newmasinblogs") but if Cookies("shoresh") is nothing then it will fail, doing it in two stages makes sure both parts aren't nothing.
 
Back
Top