The final elements of an ASP.NET page are plain old text and HTML. Generally, you can’t do without these elements—after all, HTML allows the display of the information in your ASP.NET controls and code in a way that’s suitable for users and their browsers. Let’s take a look at the literal text and HTML tags that were used to produce the display in the Visual Basic version of our sample page (the text and HTML in the C# version is identical):
Visual Basic LearningASP\VB\Hello.aspx(excerpt)
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
myTimeLabel.Text = DateTime.Now.ToString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Welcome to Build Your Own ASP.NET 3.5 Web Site!</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Hello there!</p>
<p>
The time is now:
<%-- Display the current date and time --%>
<asp:Label ID="myTimeLabel" runat="server" />
</p>
<p>
<%-- Declare the title as string and set it --%>
<% Dim Title As String = "This is generated by a code
render block."%>
<%= Title %>
</p>
</div>
</form>
</body>
</html>
The bold code above highlights the fact that literal text and HTML tags provide the structure for presenting our dynamic data. Without these elements, this page would have no format, and the browser would be unable to understand it.
By now, you should have a clearer understanding of the structure of an ASP.NET page. As you work through the examples in this book, you’ll begin to realize that, in many cases, you won’t need to use all of these elements. For the most part, your development will be modularized within code-behind files or code declaration blocks, and all of the dynamic portions of your pages will be contained within code render blocks or controls located inside a <form runat="server"> tag.
In the following sections, we’ll explore view state, discuss working with directives, and shine a little light on the languages that can be used within ASP.NET.
Visual Basic LearningASP\VB\Hello.aspx(excerpt)
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
myTimeLabel.Text = DateTime.Now.ToString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Welcome to Build Your Own ASP.NET 3.5 Web Site!</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>Hello there!</p>
<p>
The time is now:
<%-- Display the current date and time --%>
<asp:Label ID="myTimeLabel" runat="server" />
</p>
<p>
<%-- Declare the title as string and set it --%>
<% Dim Title As String = "This is generated by a code
render block."%>
<%= Title %>
</p>
</div>
</form>
</body>
</html>
The bold code above highlights the fact that literal text and HTML tags provide the structure for presenting our dynamic data. Without these elements, this page would have no format, and the browser would be unable to understand it.
By now, you should have a clearer understanding of the structure of an ASP.NET page. As you work through the examples in this book, you’ll begin to realize that, in many cases, you won’t need to use all of these elements. For the most part, your development will be modularized within code-behind files or code declaration blocks, and all of the dynamic portions of your pages will be contained within code render blocks or controls located inside a <form runat="server"> tag.
In the following sections, we’ll explore view state, discuss working with directives, and shine a little light on the languages that can be used within ASP.NET.