PDA

View Full Version : How do I create a Is Nothing Then statement using two variables in ASP.NET?


alexrjordan
02-07-2008, 01:50 AM
Using this URL:
dummy.aspx?tid=1fid=2


'Declare variables
Dim value1 = Request("tid")
Dim value2 = Request("fid")


This works:

<%
If value1 Is Nothing Then
%>
No value
<%
Else
%>
True
<%
End If
%>

This does not work:

<%
If value1 Is Nothing AND value2 Is Nothing Then
%>
No value
<%
Else
%>
True
<%
End If
%>

Spudhead
02-07-2008, 11:55 AM
A few things:

1. "Works" and "does not work" aren't particularly useful debugging statements. Post an error message, or a description of expected vs produced behaviour.

2. Don't use Request("tid"). It makes ASP go poking through all sorts of collections for your variable. Use Request.Querystring("tid").

3. "Nothing" checks for an instantiated object. You just want to see if there's something in a string:

var myValue1 = Request.Querystring("tid") & "" ' adding an empty string to a variable is an easy way of making sure the resulting variable is a String.
var myValue2 = Request.Querystring("fid") & ""
if myValue1 = "" and myValue2 = "" then
'nothing in either variable
end if