Beginning Active Server Pages

Outputting Data

Now that you've been briefly introduced to Active Server Pages, let's take a look at some of its commands. There are three main objects in ASP. Request, Response, and Server. Request generally contains information that has been sent to the page, such as form data and cookies. Response contains properties for the outputted data, headers and cookies sent to the browser, i.e. the pages Response. Server provides methods relating to the server, such as creating an ActiveX object, and some nonstandard VB commands such as HTMLEncode (converting plain text to HTML).

The command you are most frequently going to use is Response.Write, which, as you have probably already gathered, outputs text into the page. For example, if you have an ASP page with

Response.Write "<p>My First ASP Page</p>" & vbNewLine

In your browser, you would see text saying My First Page. (Note that the <p> and </p> are HTML tags, rather than normal text). Something as simple as that seems a bit pointless, however, because we are writing in Visual Basic, the string doesn't have to be preset - it could contain a variable. This means that the page could display different text depending on information sent to it. For example,

If Request.QueryString("id") = "1" Then
    Response.Write "<p>This is some different text</p>" & vbNewLine
    Response.Write "<p>This is text!</p>" & vbNewLine
End If

Now, when you first take a look at the page in a browser, you will see the text 'This is text'. However, try adding ?id=1 to the URL of the page (i.e. http://dellserver/mypage.asp?id=1). Now, when the page is displayed you see 'This is some different text'. The line Request.QueryString("id") = "1" checks to see if a parameter id has the value 1, and if it does, it displays some different text. The QueryString is the information passed after the ? in the URL - which, if you take a look at this page's URL, you can see is used for VB Web too. You will find out more about QueryStrings later in this tutorial.

You might also like...


About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” - Antoine de Saint Exupéry