Sideway
output.to from Sideway
Draft for Information Only

Content

Scripting
  ASP Server-Side Scripting
  Examples
  Scripting Language
  Examples
  Examples
  Syntax

Scripting

ASP is only a server side scripting technology along with some fundamental interface elements from Microsoft.com for running script on the server side to create HTML content dynamically. In other words, ASP is only a scripting host for the supported scripting language to provide the interactivity required for a dynamic web application solution on the server side. Script is a small program or a series of instructions written for a command interpreter to interact with the scripting host. A scripting language is needed to use as the programming language for web application development. The scripting language allows the web site builder to customization their web site by making use of the conditional and looping statements, and the built-in functions. The ASP engine of Internet Information Server provides native support for both Microsoft VBScript and JScript. Both VBScript and JScript can be used as the scripting language for ASP. Besides VBScript and JScript, other third-party ActiveX compliant Scripting engines can also be used. The key feature of these ActiveX Scripting engines is the capability of calling ActiveX objects and the built-in ASP objects. The default scripting language is VBScript.

ASP Server-Side Scripting

For the client-side scripting,  all script can be placed within the HTML document by the <script> element. That is all script is enclosed by <script></script> tags of the <script> element. The included scripting code in the HTML document will sent to the browser together with the HTML contents. But for the ASP server-side scripting, the file extension of the HTML document should be ended with ".asp" and all ASP command must be delimited with <%...%> otherwise the ASP code or scripts will not be interpreted by the ASP engine. Since the code delimited with <%...%> will be interpred before sending to the browser, the server-side script which compatible with the client-side scripting language can also be placed inside the client-side script. Besides the <script> element with "runat" attribute equal to "server" can also be interpreted as a server-side only function which can be work with the ASP script at the server-side. However, since the server-side <script> element is already running in the server-side scripting environment, the using of delimiters <%...%> in the server-side <script> element will become a syntax error.  Therefore the delimiter "<%" is to pass the control of code interpretation to the ASP engine of the current default scripting and the delimiter "%>" is to return the control of code interpretation to the web server.

Examples

Examples of ASP code
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Sample Page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    </head>
    <body>
<% strName = "ABCDE" : intCount = 3%>
Cut "<%=strName%>" to "<%=strCutName(strName)%>".
<script language = "vbscript" runat = "server">
function strCutName(strName)
strCutName = Right(strName, 3)
end function
</script>
<script type = "text/javascript">
var str = "<%=strName%>"; document.write(str.slice(2));
</script> 

    </body>
</html>
HTTP Response Output:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Sample Page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    </head>
    <body>

Cut "ABCDE" to "CDE".

<script type = "text/javascript">
var str = "ABCDE"; document.write(str.slice(2));
</script> 

    </body>
</html>
HTML Web Page Embedded Output:

Scripting Language

The default scripting language of the ASP script programming is VBScript. The default scripting language of ASP engine can also be specified by the preprocessor ASP directive, @LANGUAGE. Since the default scripting language is changed, the ASP engine should return  the control of code interpretation to the web server before the new default scripting language becomes activated, i.e. end the preprocessor ASP directive by "%>" becore continue with other script.

Examples

Examples Of ASP code
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Sample Page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    </head>
    <body>
<%@ language="jscript"%>
<%var strName = "ABCDE";%>
Cut "<%=strName%>" into "<%=strName.slice(0,2)%>".
and "<%=strCutName(strName)%>"
<script language = "vbscript" runat = "server">
function strCutName(strName)
strCutName = Right(strName, 3)
end function
</script>

    </body>
</html>
HTTP Response Output:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Sample Page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    </head>
    <body>

Cut "ABCDE" into "AB".
and "CDE"


    </body>
</html>
HTML Web Page Embedded Output:

In general, more than one scripting language can be used for the entire ASP application. For example, VBScript in server-side code and JavaScript on the client-side code. Besides server-side script other than the default scripting language can also be used with the HTML document using the <SCRIPT> element with the corresponding scripting language. Whenever there is preprocessor ASP directive, the ASP engine will process first. If the @LANGUAGE directive is present, the ASP engine will set the default scripting language accordingly. Then the ASP engine will first interpret all script in <SCRIPT> element with non-default scripting language before continue with the code after the preprocessor ASP directive.  All script in <SCRIPT> element with default scripting language will be interpretted after processing the whole HTML document. Because of the unexpected sequence of processing the <SCRIPT> element due to the complexity of the script arranged by the ASP engine, the <SCRIPT> element is usually used for containing procedures and functions only. Besides, the client-side script will be interpreted on the client browser whenever necessary.

Examples

Examples of ASP code
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Sample Page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    </head>
    <body>
<%@ language="jscript"%>
<%strName = "ABCDE"%>
Cut "<%=strName%>" into "<%//=left(strName,2)%>
<%=strName.slice(0,2)%>" and "<%=strCutName(strName)%>".
<script language="vbscript" runat="server">Response.Write("V1 ")</script>
<%="L1 "%>
Cut "<%=strName%>" to "<%=strCutJName(strName)%>".
<script language="jscript" runat="server"> Response.Write("J1 ")</script>
<script language="vbscript" runat="server">Response.Write("V2 ")</script>
<%Response.Write("L2 ")%>
<script language="jscript" runat="server"> Response.Write("J2 ")</script>
<script language = "vbscript" runat = "server">
Response.Write("V3 ")
function strCutName(strName)
strCutName = Right(strName, 3)
end function
</script>
<script language = "jscript" runat = "server">
function strCutJName(strName) {return strName.slice(2);}
Response.Write("J3 ")
</script>
End
    </body>
</html>
HTTP Response Output:
V1 V2 V3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Sample Page</title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    </head>
    <body>

Cut "ABCDE" into "AB" and "CDE".
L1 
Cut "ABCDE" to "CDE".
L2 
End
    </body>
</html>J1 J2 J3 
HTML Web Page Embedded Output:

Syntax

Since more than one scripting language can be used to build the ASP code, the syntax of ASP page is highly depending on the scripting language used in writing the web application. Aparted from the syntax of scripting language, there are also some basic rules for constructing correctly structured ASP pages.

  • An ASP page file is a text file. There is special limitation on the encoding of the file.

  • The filename extension of an ASP page file should be ".asp" except the global control setting  file , i.e Global.asa for an web application

  •  The file contents can be text, HTML tags, or server-side scripts.

  • A #include directive enclosed in a HTML comment element, e.g. <!-- #include... --> outside of the delimiter <%...%> for inserting the content of one file into the file before interpreted by the web server.

  • All ASP scripts are enlcosed between the delimiter <%...%>. All enclosed scripts will be interpreted by the ASP engine while the others will remain unchanged as original plain text and HTML tags.

  • The HTML <script> element can also be made compatible with the ASP technology by adding extra attributes, i.e. <script language="..." runat=""server">...</script>.

  • @processing directives enclosed by the delimiter <%@...%> placing at the first line of an ASP file to pass information to the web servre on how to process the ASP file..

  • An output directive enclosed by the delimiter <%= expression %>, which is equivalent to the Response.Write method, to displays the result of an expression in the form of plain text.

  • ActiveX Scripting enclosed by the delimiter <%...%> is the fundamental interface elements of the ASP technology from Microsoft. The key feature of these ActiveX Scripting code elements is the capability of calling ActiveX components, ActiveX objects and the built-in ASP objects. Each Active X elements have their only ActiveX scripting syntax.

  • ASP element

    • The delimiters "<%" and "%>" can be either on the same line with the scripts

      <% Response.Write ("<h1>ASP Sample</h1>") %>

      or on an individual line.

      <%
      Response.Write ("<h1>ASP Sample</h1>")
      %>

    • the space between the delimiter and script is not necessary because ASP engine removes white space including spaces, tabs, returns, and line feeds from both VBScript and JScript command of an ASP file. But for other scripting languages, the ASP engine preserves white space so that scripting languages dependent upon position or indentation can be interpreted correctly.

      <%Response.Write ("<h1>ASP Sample</h1>")%>

    • Comment the script between the delimiters can be done by placing an apostrophe(') at the beginning of a line. And it is better to place another apostrophe(') at the end of a line for better compatibility with JScript. Unlike the HTML comments and client-side  scripting comments, the server-side comments are removed by the interpreter during processing and no server-side comment will be sent to the browser.

      <% ' comment '%>

    • A line break can be used to indicate the end of a script command in both VBScript and JScript command of an ASP file.

      <%
      Response.Write ("<h1>ASP Sample</h1>")
      Response.Write ("<h2>ASP Statement</h1>")
      %>


©sideway

ID: 121200003 Last Updated: 5/5/2019 Revision: 1


Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339new

Travel 7new

Reference 79

Computer

Hardware 251

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 431

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Set 1

Logic 1

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019