views:

121

answers:

2

i am trying to use an ASP conditional here:

if (Request.Cookies("username")) and (Request.Cookies("password")) <> "" Then

And i keep getting this error:

Type mismatch: '[string: ""]'

Any ideas what I am getting that?

Thanks,

Ryan

+2  A: 

try

if (Request.Cookies("username") <> "") and (Request.Cookies("password") <> "") Then
hmcclungiii
Thank you...it worked great!
Coughlin
Glad I could help :)
hmcclungiii
A: 

Actually, I would do the following..

if (!string.IsNullOrEmpty(Request.Cookies("username")) &&
    !string.IsNullOrEmpty(Request.Cookies("password")))
{
    // Do your stuff, here :)
}

Get into the habit of using string.IsNullOrEmpty for testing variables and string.Empty for setting values, if u don't want a string to be null.

Pure.Krome
Hey! Thanks, how is this different from using == ""Just want to understand it since im new to ASP
Coughlin
Assuming the OP means classic ASP then your code isn't in the right language...IsNullOrEmpty sounds like a handy function to have though. I just use "if lenb(x)=0" as that serves the same purpose.
Cirieno