Library tutorials & articles

Beginning Active Server Pages

Before you start

Before you start
A few points before getting coding

  • Active Server Pages runs as part of PWS (Personal Web Server) on Windows 9x and NT Workstation, and IIS (Internet Information Server) on NT Server and Windows 2000. PWS and IIS on NT Server can be found in the NT 4 Option Pack. IIS comes as standard on Windows 2000. It will NOT run on Unix.
  • When you create an ASP page, you cannot view it on your harddisk by going to C:MyWebmyasppage.asp. It won't work! That references a direct page on your hard disk, and the server doesn't get a chance to parse any of the ASP code.
  • If you have IIS installed, it means your PC is a server (even if your PC is the only one which can access it)! You can access the pages on the server at http://localhost/ or http://PCName/. The physical location of your web site is by default C:\inetpub\wwwroot. Save your ASP pages there, and view them in a browser by visiting the URLs above.

Anyway, lets take a first look at some ASP code. Unsurprisingly, an asp page has the extension asp. In this file, you can place standard HTML. VB code can then be placed within two tags, <% and %>. As a quick example, save the following text to a file with an asp extension:

<p>This is HTML</p>
<%
'This is Visual Basic code
Response.Write "<p>hello</p>"
%>

As you can see, an ASP page is a combination of HTML and Visual Basic. Don't worry too much about the new keywords used just yet. All the Response.Write does is 'prints' "<p>hello</p>" to the rest of the page. In fact, by the time it reaches the browser, it would look like this:

<p>This is HTML</p>
<p>hello</p>

VB vs Active Server Pages

  • Standard Visual Basic Syntax Identical
  • Most standard VB 6 functions such as InStr and Replace are present
  • In Active Server Pages, you can't set the data type of a variable. The language processor decides this at run-time. (This can take some time getting used to for 'well behaved' programmers - fortunately, the Option Explicit statement remains)
  • Goto and On Error Goto statements are not supported
  • You don't compile Active Server Pages. They remain as source code, which is then parsed each time the page is executed
  • You can't display UI components such as form or message boxes
  • You can use ActiveX controls, although most users security settings will prevent them from running.
  • You can't edit ASP pages in Visual Basic. You can either edit them in notepad, Visual InterDev (part of the Visual Studio package), Developers Pad, or another programming editor

Comments

  1. 16 Dec 2006 at 21:38

        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 indeed go to the saved .asp page on my hard drive!
    So my questions:
    I have XP, so IIS is presumably installed. In the snippet below, are 'localhost' and c:\inetpub\wwwroot the actual strings to type in? For example, I currently don't have a folder called "inetpub". Do I have to create one? And where on my actual server (starman.co.uk) should I put any ASP pages?
    Alternatively, is there a good introductory book you can recommend?

    • When you create an ASP page, you cannot view it on your hard disk by going to C:MyWebmyasppage.asp. It won't work! That references a direct page on your hard disk, and the server doesn't get a chance to parse any of the ASP code.
    • If you have IIS installed, it means your PC is a server (even if your PC is the only one which can access it)! You can access the pages on the server at http://localhost/ or http://PCName/. The physical location of your web site is by default C:\inetpub\wwwroot. Save your ASP pages there, and view them in a browser by visiting the URLs above.





  2. 04 Oct 2006 at 06:26

    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

  3. 28 Dec 2004 at 08:13

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

  4. 28 Dec 2004 at 08:12

    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

  5. 12 Dec 2004 at 17:52

    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:
    <html>
    Let's see if ASP works!<br>
    <%
    Response.Write "Yep!"
    %>
    </html>

  6. 12 Dec 2004 at 17:46

    "The VB code can act on information passed to the page, such as from an internet form or a querystring (this is data passed in the URL after the ? ... take a look at this pages URL!)"


    http://www.developerfusion.com/show/1010 doesn't have a question mark in it...

  7. 31 Mar 2004 at 19:34

    you can not include a file from a remote storage site other than the one your website is being hosted on , like writing <!--#include file = " www.someplace.com/somefile.inc " --> but by using asp tear codes you can if you have any support this features.

  8. 04 Feb 2004 at 21:30

    What do I do if I need to include a file from a remote storage site other than the one my website is being hosted on. The following doesn't work anymore


    <!--#include file = " www.someplace.com/somefile.inc " -->


    or even less the " virtual " call which starts searching the virtual directory the website is stored on.


    What now?


    Do I need to write a routine to access the file remotely then spilling it onto the page using response.write???



  9. 03 Feb 2004 at 10:58

    The trick for this is to get .NET to generate a TLB library for your the .NET class. In Vs.NET, you can modify the current build profile and set the "Register for COM Interop" section to true. See http://www.c-sharpcorner.com/Code/2002/April/COMInteropP2AJ.asp for more information.

  10. 03 Feb 2004 at 08:58

    hi all,


            I am very new to ASP technology.  
            I am in a need to use DLLs (written in C#) in ASP Pages.
            Could anyone suggest me how to proceed.


    Regards,
    MAK,

  11. 02 Feb 2004 at 00:25

     i'd used ActiveX treeview control in my page and created tree by using ASP codings. but the tree is shown as collapsed one on load. i'd tried "TreeView1.Nodes(count).EnsureVisible " which produces an error of "index out of bounds". anyone pls help me as early as possible as i 've to complete by today itself. Thanks

  12. 05 Jan 2004 at 04:49

    thanks, but it wasn't the sql. i did that. it's long since solved.

  13. 05 Jan 2004 at 01:49

    chk your SQL statement. Stop before execting cConn.Execute sSQL . Print sSQL and try executing the same in the backend. If it doesnt work then you need to change the SQL statement.

  14. 13 Nov 2003 at 15:43

    i solved the problem a while ago, but i forgot how.

  15. 12 Nov 2003 at 18:18

    heppens to be that i have the same prolem.

  16. 21 Oct 2003 at 00:51

    I'm beginner of ASP.I make my thesis with ASP.But I've got problem for building project in Visual InterDev.I'd already installed IIS5.It shows web server can't connect.How I do?If it's cause of IIS error,please explain me step by step.let me know solution during five days.please help me.

  17. 15 Jul 2003 at 09:07

    It doesn't work it all. I created the table using Access and set of the OBDC fine. What's wrong?

  18. 15 Jul 2003 at 06:27

    I get this error when I submit forminput.asp:


    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'


    [Microsoft][ODBC Microsoft Access Driver] Unknown


    /forminput.asp, line 12


    What's wrong? I even copied the code over exactly.
    the error's with this line:
    cConn.Execute sSQL

  19. 23 Jun 2003 at 02:54

    Quote:
    [1]Posted by JadesNet on 22 May 2003 09:07 AM[/1]
     I tried this code out exactly, but I get an INSERT INTO syntax error.  I have also tried using the rs.AddNew to add to my database but I get a read-only error.  I have tried changing the lock type and cursor types around but I can't get anything to work.


    pls see t he comment

  20. 23 Jun 2003 at 02:53

    U Have to include a file name adovbs.inc file i yr asp page. thenu can use the addnew and update methods

  21. 22 May 2003 at 09:07

     I tried this code out exactly, but I get an INSERT INTO syntax error.  I have also tried using the rs.AddNew to add to my database but I get a read-only error.  I have tried changing the lock type and cursor types around but I can't get anything to work.

  22. 03 Jun 2002 at 20:39

    One thing to note, this only works on pages which have been posted to

  23. 01 Jan 1999 at 00:00

    This thread is for discussions of Beginning Active Server Pages.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related podcasts

  • ASP.NET Caching and Performance

    Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...