Sams Teach Yourself ASP. NET in 21 Days
Authors: Payne C
Published year: 2003
Pages: 32-33/307
Buy this book on amazon.com >>
IOTA^_^    

Sams Teach Yourself ASP.NET in 21 Days, Second Edition
By Chris Payne
Table of Contents
Day 2.  Building ASP.NET Pages


ASP.NET Programming Languages

You may be confused by this section and ask, "Aren't I learning a new programming language already?" ASP.NET is not a programming language. It's simply a framework that allows you to build applications over the Web.

Having said that, you can write your ASP.NET pages in just about any programming language you want—such as Visual Basic.NET or C# or JScript.NET. All of the code is compiled to MSIL anyway, and the compilers must emit metadata describing each application. Because of this intermediate compiler language, the JIT compiler only needs to understand MSIL. Days 3 and 4 will examine VB.NET and C#, the two most common languages for ASP.NET programming.

Because the CLR needs to ensure that all of its parts can work together, it defines a basic subset of features that every programming language must follow. Otherwise, objects developed in different languages wouldn't work together properly. This subset is called the Common Language Specification (CLS). As long as your applications only use features that are available in the CLS, they're guaranteed to work on all platforms and will be completely usable by objects compiled in other languages.


IOTA^_^    
Top
IOTA^_^    

Sams Teach Yourself ASP.NET in 21 Days, Second Edition
By Chris Payne
Table of Contents
Day 2.  Building ASP.NET Pages


Another Look at the Code

Now that you have a better understanding of how ASP.NET works, let's take another look at the code from the beginning of today's lesson, as shown in Listing 2.8.

Listing 2.8 Your First VB.NET ASP.NET Page Revisited
1:    <%@ Page Language="VB" %>
2:
3:    <script runat="server">
4:       Sub tbMessage_Change(Sender As Object, E As EventArgs)
5:          lblMessage.Text = "Hello " + tbMessage.Text
6:       End Sub
7:    </script>
8:
9:    <html><body>
10:       <font size="5">Sam's Teach Yourself ASP.NET in 21 Days:
11:       Day 2</font><hr><p>
12:       <% Response.Write("Our First Page<p>") %>
13:
14:       <form runat="server">
15:          Please enter your name:
16:          <asp:textbox id="tbMessage"
17:             OnTextChanged="tbMessage_Change"
18:             runat=server/>
19:          <asp:button id="btSubmit" Text="Submit"
20:             runat=server/><p>
21:          <asp:label id="lblMessage" font-size="20pt"
22:             runat=server/>
23:       </form>
24:    </body></html>

It's easy to spot the different sections of ASP.NET code here—in the code declaration block on lines 3-7, and in the code render block on line 12. You know what each section does as well. The first defines a method that the text box uses for its TextChanged event, and the second simply writes out "Our First Page<p>" to the browser.

Upon first request, the code declaration block is compiled into MSIL code, which is then translated into native machine code by the JIT compiler. However, the rest of the page, including the code render blocks, is evaluated at runtime—when the page is loaded into the browser.

You can also see the three server controls in the form. These act similarly to regular HTML controls, but they provide additional functionality for your application. Days 5 and 6 will examine these and other server controls.

You've also examined the importance of the runat="server" attribute. Without it, ASP.NET pages wouldn't function correctly. This attribute is the key to maintaining the viewstate, and to providing a link between what happens in the browser and the actions the server should take.

After today's lesson, you'll be able to give intricate details on this page's mechanisms, both within the .NET Framework and from a user 's perspective. You've come a long way in two days!


IOTA^_^    
Top
Sams Teach Yourself ASP. NET in 21 Days
Authors: Payne C
Published year: 2003
Pages: 32-33/307
Buy this book on amazon.com >>

Similar books on Amazon