eWebProgrammer eweb

ASP   «Prev  Next»
Lesson 8 Response.Write
ObjectiveWrite ASP variables, text and HTML code to send to a browser.

ASP Page responds to Browser Request

When a Web server sends data to a browser, it is sent as a series of data bytes.
Response.Write() lets you insert values from ASP scripts (as HTTP code) as they are created.
So far, we have seen examples of writing:
  1. Values of variables and constants
  2. Text strings (as literals and as the result of an If/Else statement)
  3. Results of calculations and functions
As you will recall, the browser never sees any ASP code that is a part of the output, because it is evaluated and replaced before being sent by the server.

Concatenating Strings

Concatenation is the process of merging two strings into one. In VBScript, the concatenation operator is the ampersand (&).
Here are examples of how concatenation works and how it can be used with Response.Write:
strResult = "Hello, " & "World"

would result in strResult containing the value "Hello, World"
strFirst = "Hello,"
strSecond = "World"
strResult = strFirst & strSecond

would result in strResult also containing the value "Hello, World"
<% Response.Write(strFirst & strSecond)%> would cause "Hello World" to be displayed on the user's browser.
In the above examples, both of the expressions are of the String subtype. Whenever an expression used in this way is not a string, ASP will convert it to a String subtype.

Writing HTML tags with Response.Write()

You can use Response.Write() to output HTML, in addition to values of ASP variables. For example, you could write:
<% Response.Write("<TABLE WIDTH='100%'>") %> 

In standard HTML the sequence for the table width (<TABLE WIDTH=90%>) includes the characters %>.
Since those characters are used by ASP as an ending delimiter, we can't use them directly, but must signal the interpreter using a back slash (\), like this:

<% Response.Write("<TABLE WIDTH=90%\>") %> 

The preferred method is the first example, which avoids the issue altogether.
The next lesson describes the three parts of ASP technology.