Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > All Around Tutorials > Serverside Scripting Tutorials
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-13-2005, 03:49 AM
  #1
Horus_Kol
Mod of the Underlay
 
Horus_Kol's Avatar
 
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 17,242
iTrader: (0)
Horus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of light
My First ASP

Requirements:
1. Access to a server with ASP installed (if the server is running IIS, then ASP should be supported)
2. A text editor to create the files
3. A working knowledge of HTML

What's this? HK is writing an ASP tutorial?!
I do actually write ASP scripts on occasion, when the job demands - and it is never a good idea to forget that there are more ways to skin a cat.
In all honesty, there is not much different functionally between the two languages - it is mostly cosmetic, in the form of the syntax that two use.


Fed up of having to make a change to multiple pages because you added a new link to your navigation bar – or need to update your disclaimer at the bottom of the page?

Well, with a simple bit of ASP, you can overcome this…

For this tutorial, I will only actually create one page as an example, but the principle will work for two, twenty, a hundred, or more, pages.

This tutorial will use vBScript for the ASP sections - it is possible to use JavaScript or even PHPScript, if the relevant software is installed on the server.

The Files

Two files are needed – index.asp and page.asp. For tidiness, I tend to put the page.asp into a sub-folder named includes or similar.

Copies of the two completed files are attached to this tutorial.

The Template

The contents of this file will be the functions to draw the template of the page – this will be the common parts of the page, including the HTML skeleton and things like the navigation bar.

For this tutorial, we will use the HTML skeleton from the HTML 101 tutorials.

Code:
  sub page_Header(title)
    ' creates the common page header HTML
    ' title = page title in browser
%>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  <head>
    <title><% Response.Write(title) %></title>
<%
    ' do not close the <head> element - allows individualisation
  end sub
The variable title allows us to modify the page title displayed in the browser – making it easier for users to find the page in a history listing. It is also a good idea for search engines.

Notice how the <head> section is not completed in this function – this is so that an individual page can have extra information placed in this section before we close it. While we would like to have as much as possible placed in a common function like this, sometimes we do need individualisation of a page.


The next function closes the <head> element, and starts the <body>:

Code:
  sub page_Bridge(heading, subheading)
    ' closes the <head> element and starts the <body>
%>
  </head>

  <body>
    <h1><% Response.Write(heading) %></h1>
    <h2><% Response.Write(subheading) %></h2>

    <hr />
<%
  end sub
The use of heading and subheading allows us to create individual headings on the page.


Code:
  sub page_Navigation()
    ' creates the navigation links

%>
    <div class='standard' id='div_nav'>
      <a href='index.asp'>Home</a> ||
      <a href='about.asp'>About</a> ||
      <a href='links.asp'>Links</a>
    </div>
<%
  end sub
The rest is all pretty much self-explanatory (and is available in the attached file)…


The Page

Once you have your template in the page.asp file, you now need to create the actual page (in this case index.asp) for display.

Code:
<%

' index.asp
' Created by: Stuart Jones
' Created on: 10th October 2005
' This file is freely distributed as part of a tutorial

%>

<!--  #include file="includes/page.asp" -->

<%
  ' this means all functions in page.asp are now available in index.asp
  
  page_Header "Example :: Home" 
  
  ' if you want to, you could put a <script> or a <style> which is required
  ' only by this page

%>
  <script src='scripts/welcome.js' type='text/javascript'></script>
<%

  page_Bridge "Example", "Home" 

  ' You could insert more individualised HTML here..

  page_Navigation  

  ' ...and here too

  page_MainStart  

  ' this is the actual content section - any valid HTML can be entered here...

%>
      <p>
        Welcome to the ASP/HTML tutorial: &quot;My First ASP&quot;
      </p>

      <p>
        I hope you find it useful.
      </p>
<%

  ' ...and now we close it all
  
  page_MainFinish  
  page_Disclaimer  
  page_Footer  
  
' ----------------------------------------------------------------------------
' END OF FILE
%>
The reason why sections are broken up into the following functions:

Code:
  page_Header "Example :: Home"
  page_Bridge "Example", "Home"
  page_Navigation
  page_MainStart
  page_MainFinish
  page_Disclaimer
  page_Footer
is that this offers a lot of flexibility in the template, with very little effort in future pages.

I hope that this is useful to anyone starting out in ASP – look out for more tutorials at HTML Forums
Attached Files
File Type: txt index.asp.txt (1.1 KB, 230 views)
File Type: txt page.asp.txt (2.5 KB, 212 views)
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak

The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
Horus_Kol is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 04-27-2007, 06:00 PM
  #2
CdnRebel
Novice (Level 1)
 
Join Date: Apr 2007
Posts: 7
iTrader: (0)
CdnRebel is an unknown quantity at this point
Question My First Asp

Hi!

I'm not sure, if this is the right forum to be asking my question. Perhaps, you could direct me. I am updating a website which was written in ASP. This is my first experience with ASP and I do not have an IIS Server so I have been posting all my changes on the website in a separate test area. My problem is that the original website and the revised version use drop down menus and I am also working with those for the first time. I am working on this basically on my own and I believe that the codes for the selections on the drop down menus is stored on a table since I have changed all the available code and according to the code, the menus should be appearing with the right selections. Unfortunately, they are still appearing with the old drop down menus. There is a table in the images file labelled Thumbs.db which I suspect carries the information that I need, but I don't know how to view the information on the table (and I am working with a copy). I am familiar with HTML and I am using notepad for the text editor. Any ideas?

Thanks,
CdnRebel
CdnRebel is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 04-27-2007, 09:58 PM
  #3
Horus_Kol
Mod of the Underlay
 
Horus_Kol's Avatar
 
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 17,242
iTrader: (0)
Horus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of lightHorus_Kol is a glorious beacon of light
well, this is a beginners tutorial...

If you have a question about your ASP script, then I would post a question, and the script to which the question applies, in the ASP and ASP.NET section of our forums
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak

The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
Horus_Kol is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 06:50 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.