ProgrammerGuide.Net | Step by Step Programmer Guide

ASP Request Object

Request Object,

Using the Request Object?
To read the value of a form field, you need to use the Request object. The Request object has four collections in total, but first we will see two collections for getting started with Request Object

Form CollectionWhen to use
QueryStringWhen the form field values are being passed through the querystring, Use this collection. So if you create a form with METHOD=GET, this is the Request collection to use.
FormWhen the form is created with its METHOD property set to POST, use this Request collection.

To use these collections, you use the following syntax:


The VariableName is always the NAME property from the form field that you are interested in. For example, let’s us say that you created a text box in your form creation web page with its NAME property set to ‘ Age ‘. If, in your form process script, you wanted to save the value of text box into the variable name’ iAge ‘, you could do so with the following code in listing (assuming that the form’s METHOD property was set to GET).

<%@ Language=VBScript %>
<% Option Explicit %>
    ‘Create a variable named iAge and Store
    ‘into it the form field “Age”

     Dim iAge
     iAge = Request.QueryString(“Age”)

     Response.Write “iAge = ” & iAge

Remember that the form field values are passed to the form processing script via a string of name/value pair. Each name and value is separated b an equal sign (=), and each name/value pair is separated from one another with an ampersand (&). Form example, the string might look like this:


You can access each one of these variables separately by using Request.QueryString or Request.Form collection. What collection you would use depends on the form’s METHOD property. The following code would assign the name/value string passed through the querystring to the variable strFormFieldValue:<%
      Dim strFormFieldValue          
      StrFormFieldValue = Request.QueryString
If the form field values where sent via POST METHOD, you would want to modify line 3 to read:

      StrFormFieldValue = Request.Form

One nice thing about collections is that you can easily step trough all the items using a For Each…..Next control structure.

Accessing the HTTP Headers
request header is a single line of text that your browser sends to the web server when requesting to view any web page. A browser can send no headers, or several headers. Mainstream browsers all send a set of common header. Header sent to the web server from the client (the browser) are called request header because they ‘re sent when the client request a particular web page.

When the server sends back the required Web page to the client, it also sends a set of headers, known as response headers. Response header are additional bits of information about the Web page being sent to the client. Both the request headers and its response headers are referred to, more generally , as HTTP header.

Using HTTP Headers
For sending HTTP header, you can use the AddHeader method of the Response object. The syntax of AddHeader method is as follows:

Response.AddHeader HeaderName, HeaderValue.

Please click here for related products on Amazon!


Add comment

Want to Check Celebrities News?