Although ASP is used primarily to create and process server-side scripts, you can extend its effectiveness by using it to generate client-side scripts which are then processed by the client browser. You can write server-side scripts that put together script commands that are sent to the browser.
You do this by combining client-side scripts that are enclosed by HTML comments with server-side scripts that are enclosed by delimiters:
<SCRIPT LANGUAGE="VBScript"> <!-- client script <% server script %> client script <% server script %> client script ... --> </SCRIPT>
With this functionality in your scripts, you can create exciting applications. For example, the following script will create several client-script subroutines that run on the user's Web browser.
<% ServerTime = Time ServerDate = Date For i = 1 to 4 Randomize GreetCondition = int(rnd * 3) %> <SCRIPT LANGUAGE="VBScript"> <!-- Sub ServeInfo<%= i %>() Select Case <%= GreetCondition%> Case 0 Msg = "Hello, the time is <%= ServerTime %>." Case 1 Msg = "Welcome! Today's date is <%= ServerDate %>." Case 2 Msg = "Hi, the time is <%= ServerTime %> and the date is <%= ServerDate %>. End Select Document.Write Msg End Sub ServeInfo<%= i %>() //--> </SCRIPT> <br> <% Next %>
In the previous script, ASP retrieves time and date information from the server, and then loops several times to create subroutines that execute on the user's Web server. Each of these client-side subroutines render a randomly selected greeting, displaying the time and date information.
Scripts of this kind can be expanded, for example, to retrieve and deliver configuration information to a special client-side script or component, such as an ActiveX control. Through clever use of this scripting technique, you can also reduce the amount of time that your Web server spends processing and returning user information requests.