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!
|