Maybe it's trivial question, but I have no idea what is the type of Request.QueryString()
. When I check it with typeof - it says it's Object. How to check which object it is and which property of that object is a string in URL?
I'm doing it server side with language specification <%@ language="javascript"%>
If I've got URL like that:
http://127.0.0.1/Kamil/Default.asp?name=
then how to check if name is empty? It's not null. I know I can convert Request.QueryString("name")
to String and check if it's empty string "", but is it proper way?
The Request collection is an object that inherits IRequestDictionary interface.
In JScript, it's a good practice to use item to get actual value, not the implicit one due to values of the QueryString collection (also Form and ServerVariables) are IStringList in fact.
You said you know C# so you'll understand the following fictitious QueryString declaration.
And a few examples how you should check the values in JScript without string conversion.
The result of
Request.Querystring
(with no name provided) is a string. The result ofRequest.Querystring("name")
depends on whether "name" is part of the querystring, and if it is, whether it has a value.So, given the following querystring:
If you read them into variables:
you'll get the following results: x =
"1"
(a string), y =""
(a blank string), and z =Empty
(a special value which will be silently converted to a string or a number depending on how you use it, i.e. bothEmpty = ""
andEmpty = 0
are in some sense true).