Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  advice: Secure Code and Data
     [next Lesson]  advice: CASE reads better than IF

Encapsulate Your Code in Reusable Libraries

You should create many subroutines and functions and instead of placing them in each page just use the include facility to access them. The following scripts are very compact because they call SUBroutines that the include files contain.

Here someone has encapsulated HTML coding into a high level ASP call:

   filename=/learn/test/htmldemo.asp

<Test Script Below>


<!--#include virtual="/learn/test/lib_htmlstuff.asp"-->
<html><head>
<title>libhtmldemo.asp by Phil Paxton</title></head>
<body>
<form action="lib_htmldemorespond.asp">
<%
    Call Form_TextBox("first name","Fname",20,20,"")
    response.write "<br>"
    Call Form_TextBox("Last Name","Lname",20,20,"")
    response.write "<br>"
    Call Form_TextBox("City","cy",20,20,"")
    response.write "<br>"
    Call Form_TextBox("State","st",2,2,"")
    response.write "<br>"
    Call Form_TextBox("Zip Code","zp",10,10,"")
    response.write "<br>"
    Call Form_SubmitButton("Register Me","register")
%>
</form>
</body>
</html>

Here displaying a listbox from a database has been simplified by a subroutine:

   filename=/learn/test/subdblist.asp

<Test Script Below>


<html><head>
<TITLE>subdblist.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<form>
<% 
theDSN="DSN=student;uid=student;pwd=magic"
call query2list("city","publishers","cy",theDSN,"Rockville")
call query2list("state", "publishers","st",theDSN,"MD")
call query2list("zip", "publishers","zp",theDSN,"20851")
%>
</form>
<!--#include virtual="/learn/test/subdblist.inc"-->
</body></html>

The library files/includes that make all these tasks one step are detailed at:
/freebook/asp/qualitycode.aspx

There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too. a $5 tip buys him lunch at McDonalds, a $20 tip buys his kid Hitoshi a new computer game, a $39 tip buys his daughter Michiko a few nice outfits. See our donor list.