Check if it is empty. There are several different ways, but the one I saw most often looks like this:
If Request("FieldName") <> "" Then 'etc. End If
I usually explicitly check the Form and QueryString collections with some change to one of the codes below, if I can get a variable from one or the other depending on the context:
Select Case True Case Request.Form("FieldName") <> "" 'Run if the Form isn't empty Case Request.QueryString("FieldName") <> "" 'Run if the QueryString isn't empty Case Else 'Set a predefined default if they're both empty End Select
Or a nested If ... Then:
If Request.Form("FieldName") <> "" Then 'Run if the Form isn't empty ElseIf Request.QueryString("FieldName") <> "" Then 'Run if the QueryString isn't empty Else 'Set a predefined default if they're both empty End If
If I know exactly what collection he is going to, I will check this collection on purpose. The reason is because I want to make sure that it pulls what I expect from where I expect it to happen. I don't want anyone overriding the Form value by sending something to a QueryString when I did not expect this.
From MSDN :
If the specified variable is not in one of the previous five collections, the Request object returns EMPTY.
Access to all variables is possible directly by calling Request (variable) without a collection name. In this case, the web server searches for the collection in the following order:
- Querystring
- The form
- Cookies
- ClientCertificate
- ServerVariables
If a variable with the same name exists in more than one collection, the Request object returns the first instance of the meeting object.
It is strongly recommended that the full name be used when referring to members in the collection. For example, instead of Request. ("AUTH_USER") uses Request.ServerVariables ("AUTH_USER"). This allows the server to find the item faster.
source share