Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 205,319 times

Contents

Related Categories

Beginning Active Server Pages - Outputting Data

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

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Re: [1010] Beginning Active Server Pages - absolute beginner!

    Posted by michael poxon on 16 Dec 2006

        Hi,
    When I say I'm an ASP beginner, I mean it! I've only written one trivial bit of code, and got a blank page. I see now that's described in the article snippet below. I did ind...

  • .I want to know how to save the files.whats the extensions...

    Posted by writetoksk on 04 Oct 2006

    hi,


    its first i started ASP.I want to know how to save the files.whats the extensions...Where can i get the sample programs

  • Posted by James Crowley on 28 Dec 2004

    Are you running IIS ? And are you viewing it in your browser via the correct URL? (ie something starting with http:// rather than file:// ) ?

  • Posted by James Crowley on 28 Dec 2004

    It does - you just can't see it ;) We've got an ISAPI filter that rewritse /show/1010/ to something like /show.aspx?id=1010

  • It's not working ;_;

    Posted by HyperHacker on 12 Dec 2004

    Is there something special I have to do besides saving it as a .asp file, or does it just not work on my server? It just spits out the code, even HTML, as plain text.

    [code]
    Let's see if ASP...