Simple Data Output |
|
In a regular web page, to display something, you can simply type it between the <body> and the </body> tags. You can optionally use various tags to format the text for better display. Here are examples: <html> <head> <title>Active Server Pages Tutorials</title> </head> <body> <h1>Lesson 2: Active Pages</h1> <p>This lesson shows different ways of displaying items on a web page. The instructions involve both HTML and scripts</p> <h3>Enjoy</h3> </body> </html> This would produce: In the same way, you can use all HTML tags that are appropriate for your task. To support the display of items on a web page, Active Server Pages provides an object called Response. This object is equipped with different methods for different tasks. The method used to display something on a web page is called Write. Its syntax is: Reponse.Write(Something) The item to display must be passed as argument. If you want to display an empty space, a character, or a group of characters, pass it double-quoted in the parentheses of this method. Here is an example: <html> <head> <title>Active Server Pages Tutorials</title> </head> <body> <h1>Lesson 2: Active Pages</h1> <% Response.Write("Lecturer: Benjamin Jacobson") %> <p>This lesson shows different ways of displaying items on a web page. The instructions involve both HTML and scripts</p> <h3>Enjoy</h3> </body> </html> This would produce: If the item to display is a regular number, whether natural or decimal, you can pass it directly to the method. Here is an example: <html> <head> <title>Active Server Pages Tutorials</title> </head> <body> <h1>Lesson 2: Active Pages</h1> <% Response.Write("Lecturer: Benjamin Jacobson") %> <p>Time Allocated: <% Response.Write(52) %> minutes </p> <p>This lesson shows different ways of displaying items on a web page. The instructions involve both HTML and scripts</p> <h3>Enjoy</h3> </body> </html> |
This would produce:
|
Responding to HTML Tags |
When you write HTML tags in your code, the browser would interpret them and publish a result to the user. As opposed to HTML tags, most of the scripts you write are not directly intended to your user's browser. They are presented to the web server that analyzes the script and responds to it. In fact, if you include Active Server Pages scripts in the <% and the %> delimiters, when the resulting page is presented to the user, the script sections are removed. This also means that a curious visitor would not even know what your code looks like. For example, here is the code presented to the browser from the above web page: When a file with active code is sent to the server, the server checks the <% %> sections and their contents. Any section that contains, for example, double-quoted strings passed to the Response.Write() method is considered "as is". The server would remove <%, the Response.Write() method, its double-quotes, and %>. This means that, whatever you pass to this method would be sent to the browser the same way you passed it. This allows you to include HTML tags as part of the Response.Write() argument but it is your responsibility to send it as regular HTML code. If you make mistakes, they would be presented to the browser, the server might not care and the server cannot or would not fix it. Based on this, you can include normal HTML code and pass it to the Response.Write() method. Consider the following example: <html> <head> <title>Active Server Pages Tutorials</title> </head> <body> <h1>Lesson 2: Active Pages</h1> <% Response.Write("<b>Lecturer:</b> Benjamin Jacobson") %> <br> <% Response.Write("<b>Time Allocated:</b> <i>52 minutes</i>") %> <p>This lesson shows different ways of displaying items on a web page. The instructions involve both HTML and scripts</p> <h3>Enjoy</h3> </body> </html> When the server receives this code, it removes the <% Reponse.Write(" and the ") %> sections. Then its sends the rest to the browser: The browser then receives normal HTML tags that it must interpret and present the result in the intended web page:
In the same way, you can write any sophisticated HTML code and pass it to the Reponse.Write() method. This consequently means that if you pass bad HTML code to a Response.Write() method, the result may be unpredictable. |
Language Support |
Introduction |
You are probably familiar with the fact that, to write a Windows application, you must use a computer language. This also applies to the Internet. Although you can create a plain text-based file and save it as text then display it in a browser, you usually use HTML as a language to give better instructions to the browser, with tags. When it comes to scripting also, you must choose a language to write your instructions in. The default language of Microsoft Internet Information Services, thus ASP, is Visual Basic Scripting Edition or VBScript. Besides VBScript, you can also use JavaScript or Microsoft JScript. |
Your Language of Choice |
By default, Active Server Pages is primarily supported with VBScript. Other languages are supported also. To specify the language of your choice, in the first line of your page, you can use the following formula: <%@ Language="FavoriteLanguage" %> The FavoriteLanguage factor must be the name of the language you use for your code. It can be VBScript, JavaScript, JScript, or else. For example, if you will be using VBScript, you can write this line as: <%@ Language="VBScript" %> Here is an example: <%@ Language="VBScript" %> <html> <head> <title>Active Server Pages Tutorials</title> </head> <body> <h1>Lesson 2: Active Pages</h1> <% Response.Write("<b>Lecturer:</b> Benjamin Jacobson") %> <br> <% Response.Write("<b>Time Allocated:</b> <i>52 minutes</i>") %> <p>This lesson shows different ways of displaying items on a web page. The instructions involve both HTML and scripts</p> <h3>Enjoy</h3> </body> </html> In the same way, you can replace VBScrip in the above code with JavaScript or JScript. It is important to note that this is not case-sensitive. As you may be aware, each language has its own rules that you must follow when programming in it. Just changing the name of the language from the above line and leaving the rest of the code unchanged doesn't complete the job; in fact, simply changing the name of the language is a guaranty that some of the code on the page would not work anymore. |
Accessories For Code Writing |
Code Comments |
In the programming world, a comment is text that the compiler would not consider when reading the code. As such a comment can be written any way you want. In VBScript, the line that contains a comment can start with a single quote. Here is an example: ' This line will not be considered as part of the code Alternatively, you can start a comment with the Rem keyword. Anything on the right side of rem, Rem, or REM would not be read. Here is an example: Rem I can write anything I want on this line Comments are very useful and you are strongly suggested to use them regularly. They can never hurt your code and they don't increase the size of your application. Comments can help you and other people who read your code to figure out what a particular section of code is used for, which can be helpful when you re-visit your code after months or years of not seeing it. |
Line Continuation: _ |
You will regularly need to expand your code on more than one line. This happens if you are writing an expression that involves many entities that must belong to a group. To continue a line of code to the next, type an empty space followed by an underscore symbol, then continue your code on the next line. |
The Carriage Return-Line Feed Constant |
Visual Basic provides the vbCrLf operator. It is used to interrupt a line of text and move to the next line. |
|
||
Previous | Copyright © 2005-2016, FunctionX | Next |
|