Download Tips to Becoming a Better ASP Coder / PDF

Download Tips to Becoming a Better ASP Coder / PDF










Download Tips to Becoming a Better ASP Coder / PDF
























What Exactly Are Active Server Pages?

Active Server Pages, commonly referred to as ASP, is Microsoft's solution to server-side scripting. With simple HTML pages, the client (a web surfer) requests a web page from a server (some www.blah.com). The server just sends the file to the client, and the page is shown on the client's browser.

With Active Server Pages, the server gets a chance to alter the file before sending it to the user. So, for every request for a file with a .ASP extension, the server runs the file through a DLL called ASP.DLL, which parses the ASP commands.

To use Active Server Pages you must be running a Microsoft webserver; Microsoft makes a number of Web servers that are freely available. If you have Windows NT 4.0 Server installed, you can download IIS 3.0 or IIS 4.0, both of which support ASP development. If you have Windows 2000, you can use IIS 5.0. If you have Windows 9X or Windows NT Workstation, you can use Personal Web Server (PWS).

 All of these products can be downloaded for free from Microsoft's Web site: http://www.microsoft.com/iis/
If your web site is run on a UNIX box, you can still use Active Server Pages, but you need to use a third party tool to translate the ASP before it is sent to the client. Such companies like Chilisoft make products of this nature.

If you are running a Microsoft Web server, to run an ASP file, all you need to do is create a file on the webserver with a .ASP extension. When the browser requests the file, the webserver is smart enough to preprocess the file before sending it off to the client.

You can have your ASP code connect to a database (SQL, Access, Oracle, Informix, or any ODBC-compliant database) and dynamically insert the data into your HTML pages. This leads to some very powerful possibilities including ECommerce, customizable sites, data entering / retrieving systems run over the Internet, and a slew of other possibilities. You can view some web sites that use ASP by visiting most any Microsoft sponsored site such as MSNBC.com or The Zone.


Why ASP?

Before you decide to use ASP to implement your web application, you should do some serious thinking to determine if ASP is the correct solution for your particular problem.
If you need a dynamic web site, with database connectivity, and you already are using IIS 3.0 or up, then ASP is obviously the simple choice. If you are using a UNIX server and want to use ASP, you have two options:
  • Buy a third part product, like Chilisoft, to run your ASP on a non-Microsoft web server, or
  • Move your site to a host who provides NT webservers.

There are many advantages to using ASP. They include database connectivity, the ability to create dynamic web sites, and the ease with which you can create web sites to sell inventory on the web. ASP is nice because it is free! ASP's biggest advantage, in my opinion, is that it is easy to learn, especially for those who are familiar with VisualBASIC.

There are also non-Microsoft development tools for sale to create dynamic web sites, but those products (such as Cold Fusion) aren't free. ASP, however, is!

It is easier, in my opinion, to write dynamic sites using ASP than it is using Perl on a UNIX box. UNIX webservers are more stable than NT servers, though, and Perl script will most often run quicker than ASP script.
In summation, if you have a Microsoft webserver, the choice is pretty obvious if you want a dynamic website.

ASP Basics: What's Happening Back There?

With each new language it seems computers get easier and easier to program. When computers first came into existence, programmers needed to know very cryptic and specific machine instructions to make those ancient behemoths do anything. Before too long assembly languages arose, and then high-level programming languages were introduced with the creation of Fortran. Today we have reusable components, GUI/WYSIWYG designers, and easy to use scripting languages.

As computers become easier and easier to program, though, developers have to know less of what's happening in the bowels of the compiler or interpreter. While this saves time, I think it is important to have a firm grasp on what's going on behind the scenes. I think this is an important thing to know for two reasons: one, it's cool; two, having a better understanding of what's really happening leads to better written code, fewer bugs, and an improved self-esteem!

Before we begin discussing how ASP pages "work," let's talk about how static HTML pages "work." The Internet is built on a client/server foundation. That means that there are two parts we must look at when dissecting an Internet transaction: the client and the server. The client is the web browser, be it Internet Explorer, Netscape, Lynx, Opera, or whatever. The server is the web server on which the HTML page exists.

The entire process of retrieving a web page goes like this:
  • You type in the URL into your browser, for example http://www.yahoo.com/index.html
  • Your browser finds the appropriate web server, and to that server says, "I need to look at the file /index.html, please."
  • The web server locates the file /index.html and sends it to the browser as HTML text.
  • The browser collects this text and parses it, determining how to display those colorful animated gifs and blinking text we've all come to love.
It's that simple. The transaction has just three simple steps: the client requests the document, the web server sends the document, the client decides how to display it. With ASP, however, there are some additional steps are taken on the server before the HTML text is sent back to the client. Let's look at what happens with ASP:
  • You type in the URL into your browser, for example http://www.ASPisNeat.com/default.asp
  • Your browser finds the appropriate web server, and to that server says, "I need to look at the file /default.asp, please."
  • The web server locates the file /default.asp and parses out the ASP code, turning all of the ASP code into applicable HTML code. ASP code is code inbetween the ASP script delimiters (<% ... %>) or in OBJECT tags with the RUNAT=Server property set. Since all of the ASP is parsed into HTML, the client sees absolutely no ASP code!
  • The browser collects this HTML text and parses it, determining how to display those colorful animated gifs and blinking text we've all come to love.
You'll note that there is again just three steps, although the second step is a bit more involved. The whole process starts with the client requesting a file with a .ASP extension. The web server notes the extension, and since it has a .ASP extension (as opposed to a .txt, .htm or .html), the server parses the contents of the requested file before sending it to the client. So when you view an ASP file through IE or Netscape, your browser doesn't know that the .asp file is any different from a standard .html file!

One of the things that makes ASP a bit tricky for beginners is the fact that there is two kinds of scripting: client-side scripting, and server side scripting. Client-side scripting is HTML code that the browser interprets. For example, you can have a message box appear when a page is loaded by adding:
 
at the bottom of your HTML page. This is client-side scripting. The web server makes no note of client-side code, it just sends it to the client like regular HTML text. It is the client's responsibility to process client-side scripts.
Server-side scripts, like ASP, are scripts that the web server processes. Since server-side scripts are processed by the web server, the client (or browser) does not interact with the server-side scripts. Since all ASP code is processed before the client obtains any client-side script, it is impossible for ASP to make use of client-side actions without requiring a round trip to the server.
You can insert server-side variables into client-side script. Since the server-side script will be processed before the client receives the HTML content, and since client-side scripts are synonymous with HTML content, you can write server-side script variables to the client-side scripts rather simply.
<%
               Dim strMessage
               strMessage = "Hello, world!"
%>
 
What you cannot do is have server-side script make use of client-side variables, methods, or events. Since the server-side script has completely been processed by the time any client-side code is processed, client-side code cannot impact the server-side code in any way. If you want to take a server-side action based on a client-side event, you must make a round-trip to the server.
Finally, in case you were wondering, the reason you get an error if you try:
<%
               MsgBox ("Hello World!")
%>
is because the function MsgBox is a client-side function (it displays a message box on the client's screen). Since it is strictly a client-side function, it is not available for server-side scripting. Hence the error.
I hope this article has helped you better understand the difference between the client and server when it comes to the Internet, and, hopefully, you've gained a better understanding of how ASP pages are processed.



Getting Started with ASP
By Akshay Luther

Welcome to the wonderful and exciting world of ASP. This article is focussed on passing on knowledge and information that I have had to acquire the hard way in a nice compact high-powered package. For more beginner-level ASP information, also be sure to check out the Beginner ASP FAQs on 4Guys.
Skip the next few paragraphs if you already know what ASP and are familiar with the client/server model for web applications.
Well, what is it? ASP is a server-side Microsoft technology that provides an environment for Server Side programming. It lets you use either Jscript (Microsoft's version of JavaScript) or more commonly VBScript to write scripts that execute on the server. So why is it so cool? Primarily, because it lets you create HTML on-the-fly. It lets you do this based on, for starters, two very ..........




















Download Tips to Becoming a Better ASP Coder / PDF

0 commentaires: