To read the article online, visit http://www.4GuysFromRolla.com/webtech/082399-1.2.shtml

ASP Basics: What's Happening Back There? (Part 2)


  • Read Part 1

  • 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:

    <SCRIPT LANGUAGE=JavaScript> alert("Hello, world!"); </SCRIPT>

    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!"
    %>
    
    <SCRIPT LANGUAGE=JavaScript>
    	alert("<%=strMessage%>");
    </SCRIPT>
    

    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. For a discussion on why we should want to program web pages using ASP, be sure to read the article Why ASP?

    Happy Programming!


  • Read Part 1

  • Article Information
    Article Title: ASP Basics: What's Happening Back There?
    Article Author: Scott Mitchell
    Published Date: Monday, August 23, 1999
    Article URL: http://www.4GuysFromRolla.com/webtech/082399-1.2.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers