|
I will now explain the code in Listing 1.0.
<%@ Page Language=”VB” %>
This is the first line of code you see in Listing 1.0 and it is essential that all ASP.NET pages have this as their starting line. This declaration is called Page directive and is used to specify certain settings for an ASP.NET page. The settings are specified as attributes in the directive. You can see one example of a setting, Language, specified. This setting identifies that the coding language used for this ASP.NET page is Visual Basic.NET. If you were to use any other language for coding the page, you would specify its name here. For example; C# for C-Sharp, J# for J-Sharp, etc.
There may other settings available for Page directive which you will come to learn as your knowledge in the technology progresses.
Following the Page directive is a set of code lines enclosed in the script tags. The opening <script> has two attributes, Language and Runat.
<Script Language=”VB” Runat=”server”>
...
...
...
</Script>
The Language attribute indicates the programming language used in this block. Since we have already specified the language attribute in Page directive, this attribute is optional here and can be omitted.
The Runat attribute indicates that this tag and its enclosed code are to be executed on the server-side. So during parsing when asp_net.dll comes across any tags having the Runat attribute set to the value server, it will pass that code to the specified language’s compiler for execution.
Public Sub Page_Load() Response.Write (“Hello World”) End Sub
Given above are the lines of code enclosed in the <script> block. Page_Load() is an event of an ASP.NET page that fires when the page loads in the browser. Any code that you specify within this event will execute at the page load time and before anything else in the page.
Within the Page_Load() event, I invoke the Write method of the Response object passing it the “Hello World” string literal. The Response object in ASP.NET represents the response stream that is sent back to the client requesting the page (explained earlier in the section Static and Dynamic Web sites).
The lines of code following the <script> block are simple HTML in which I only set the title of my ASP.NET Web page.
|