When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Monday, August 23, 1999

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:

    - continued -

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

    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

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article