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
Else
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.
Comments