Not Out of Place:
Below is the ASP Script for Lesson 02.
Click Here to run the script in a new window.
Remember in Lesson 01 how the entire HTML output was on one line. The escape characters allow us to add carriage returns.
Below is the HTML source code as seen on the client side.
<HTML> <FONT COLOR="red">"Hello World"</FONT><BR> <FONT COLOR='blue'>'Hello World'</FONT><BR> </HTML>
I've reprinted a single line of ASP script below. Look at the "/r" at the end of the line.
Response.Write("<FONT COLOR=/"red/">/"Hello World/"</FONT><BR>/r")
The "/r" is a special character representing a carriage return. It's how I got the separate lines of HTML output on ...well... separate lines. That's vitally important on larger applications and larger pages. I said it before, but I'll say it again. Trust me; you can't find bugs if you can't even make heads or tails of what you're putting out to the client.
There's something else you should notice. See how I put the backslash underneath some of the quotation marks. What would happen if I remove the backslashes? Let's try the following line of code.
Response.Write("<FONT COLOR="red">"Hello World"</FONT><BR>")
I would get an error code, which is copied below.
Microsoft JScript compilation error '800a03ee' Expected ')' /asp/Section01/Script02.asp, line 4 Response.Write("<FONT COLOR="red">"Hello World"</FONT><BR>") -----------------------------^
What if I don't like Escape Characters? Do I have to use them?
You can limp along without them. Consider the line below.
Response.Write("<FONT COLOR='blue'>'Hello World'</FONT><BR>")
|/0nn||ASCII Escape Characters|
You can interchange single quotes with double quotes. It's awkward, in my opinion. But it works. Even with that said, HTML aesthetics are the least important reason to use Escape Characters.
A far more important reason to utilize escape characters is that it allows us to output a whole list of special characters.
But the most important reason to use Escape Characters (at least for any sophisticated application) is for your database connection. (Database connections get their own lesson later on.) Compare the two Connection Strings below.
var Connection="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("//TopLevelVirtualFolder") + "//database//myDatabase.mdb;"
Connection="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/TopLevelVirtualFolder") & "/database/myDatabase.mdb;"