August 26, 2002 - Client-Side vs Server-Side Scripting | WebReference

August 26, 2002 - Client-Side vs Server-Side Scripting

Yehuda Shiran August 26, 2002
Client-Side vs Server-Side Scripting
Tips: August 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

In ASP.NET pages, JScript .NET functions and variables should be defined within <SCRIPT> blocks, while executable code must be enclosed within <% %> blocks. This is very different from the way you code JavaScript on the client side. Client-side JavaScript allows placing of executable code anywhere inside <SCRIPT> blocks.

The following ASP.NET page demonstrates the separation of function definitions and executable code. The function output() is defined in the <SCRIPT> block. The executable code that calls output() is placed inside the <% %> brackets:

  <%@ Page LANGUAGE="JScript" SRC="col116ex6.aspx.js" INHERITS="COL116.codeBehind" 
    AutoEventWireup="true" EnableViewState="true"%>
  <SCRIPT LANGUAGE="JScript" runat="server">
  function output(str) {
  var today : Date = new Date();
    <TITLE>Hello World Test</TITLE>
  <BODY STYLE="font-size:12; font-family:arial,verdana,sans-serif;">
    <P ALIGN="center">Today's date is  <% output(today); %></P>
    <FORM RUNAT="server">
    <P ALIGN="center"><ASP:LABEL ID="message" RUNAT="server"></ASP:LABEL></P>
To learn more about JScript .NET and ASP.NET, go to Column 116, JScript .NET, Part X: Displaying Information.