Datasheet

<form id=”form1” runat=”server”>
<asp:TextBox ID=”TextBox1” runat=”server”></asp:TextBox>
<asp:Button ID=”Button1” runat=”server” OnClick=”Button1_Click” Text=”Button”/>
<asp:Label ID=”Label1” runat=”server”></asp:Label>
</form>
</body>
</html>
The code-behind file referenced by HelloWorld.aspx file is HelloWorld.aspx.cs, which is defined as
follows:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class HelloWorld : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text;
}
}
As you can see, HelloWorld.aspx contains the markup and HelloWorld.aspx.cs contains the code.
The
Inherits attribute in the @Page directive identifies the code-behind class, while the CodeFile
attribute identifies the file containing the class. Note the absence of any fields in the HelloWorld class
providing mappings to controls in the ASPX file. Old-style code-behind is still supported, but this new
model is now the preferred one. Not surprisingly, Visual Studio 2005 supports the new model natively.
Creating and Sharing Reusable Components in ASP.NET 2.0
Prior to ASP.NET 2.0, if you were to reference a reusable component from your ASP.NET application,
you had to compile the assembly and place it in the bin folder (or place it in the GAC) of the web appli-
cation. But now with ASP.NET 2.0, creating a reusable component is very simple and straightforward.
All you need to do is create the component in a predefined subdirectory called
App_Code. Any compo-
nent placed in this directory will be automatically compiled at runtime into a single assembly. This
assembly is automatically referenced and will be available to all the pages in the site. Note that you
should only put components in the
App_Code subdirectory.
New ASP.NET 2.0 Controls
ASP.NET 2.0 introduces several new controls that help create data-driven web applications. These con-
trols perform actions, such as connecting to a database, executing commands against the database, and
so on, without you even having to write a single line of code. ASP.NET 2.0 introduces more than 40 new
control types to help you build rich web UIs while insulating you from the vagaries of HTML, client-side
script, and browser DOMs. The following table lists the new control types.
Control Category Controls
Data source controls SqlDataSource, ObjectDataSource, XmlDataSource, Access-
DataSource
, SiteMapDataSource
Data-bound controls GridView, DetailsView, FormView, TreeView, Menu
Table continued on following page
7
Chapter 1: Introduction to ASP.NET 2.0
05_041796 ch01.qxp 12/29/06 9:09 PM Page 7