One of the first things to learn in ASP is how to create output. With a few simple commands, you can write out the current date and time, the user’s browser information, and much, much more!
How does this work? Well, remember, ASP itself isn’t ever visible to the user, It works behind the scenes. ASP can, however, display regular HTML tags, and text, and other HTML commands to the user’s browser. The user’s browser then interprets them as regular HTML and displays them just as if you had hard coded that information into a page.
What do I mean? Well, say you wanted the words
to appear to someone coming to the page index.asp. Let’s say you wanted to use ASP to display those words. First, you would start with the “starting ASP” indicator. You always use this before you give any ASP commands, so your browser knows that what is coming next shouldn’t be shown to the user.
The <% is the way the browser knows to switch to ‘ASP mode’ where it starts processing what you tell it to do. Now you want to give the ASP command to write out some text. So you would put:
Response.Write “Hello, World”
That line tells the ASP interpreter to take the text “Hello, World” and write it out to the browser. You end with the ‘end of command’ marker –
and that’s it! So your entire file, with the normal HTML starting and ending, would look like this:
Response.Write "Hello, World"
That’s it, you’ve done your first ASP page! Wasn’t that easy? But heck, if you were just going to write “Hello, World”, you wouldn’t need ASP to do it. The great part about ASP is that you can write ANYTHING ASP knows about, which includes results from calcuations, retrievals from database queries, and much, much more.
Let’s say you have a page in which you have all sorts of other HTML, and then at one spot you decide you want to show the user the current date and time. You can’t code that into a web page, because it’s always changing! However, since ASP is interpreted as the page is being displayed, IT always knows what time it is. So instead of putting
THIS IS THE CURRENT TIME
you would put
and when the program ran, it would show the current time! There are MANY applications for writing with ASP. I cover a variety of specific examples in the rest of this website.
This page is lesson three in my free ASP Classic Course. Click below to enjoy the full course from start to finish!