New Code-Behind Model in ASP.NET 2.0
ASP.NET 1.x supports two coding models: the inline model, in which markup and
code coexist in the same ASPX file, and the code-behind model, which places
markup in ASPX files and code in source code files. ASP.NET 2.0 introduces a
third model: a new form of code-behind that relies on the new partial classes
support in the Visual C# and Visual Basic compilers. Code-behind in ASP.NET 2.0
fixes a nagging problem with version 1.x: the requirement that code-behind
classes contain protected fields whose types and names map to controls declared
in the ASPX file.
The following code listing shows the .aspx file named HelloWorld.aspx:
<%@ Page Language=”C#” CodeFile=”HelloWorld.aspx.cs” Inherits=”HelloWorld”
<form id=”form1” runat=”server”>
<asp:TextBox ID=”TextBox1” runat=”server”></asp:TextBox>
<asp:Button ID=”Button1” runat=”server” OnClick=”Button1_Click”
<asp:Label ID=”Label1” runat=”server”>
The code-behind file referenced by HelloWorld.aspx file is HelloWorld.aspx.cs,
which is defined as follows:
public partial class HelloWorld : System.Web.UI.Page
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.
More Related links
This includes explanation of code security, Principal object, declarative and
imperative security, role-based security, code access security and code group.
This article explains .Net assembly, private and shared assembly, satellite
assemblies, resource-only assembly, ResourceManager class, strong name, global
Here you can learn about break mode, options to step through code in .Net, Debug
Vs Trace in .Net, trace class, listeners collection of Trace and Debug objects
and Trace Switches.
ASP.NET 2.0 ships with a Web Parts Framework that provides the infrastructure
and the building blocks required for creating modular web pages that can be
easily customized by the users. You can use Web Parts to create portal pages
that aggregate different types of content, such as static text, links, and
content that can change at runtime..................
Visual Studio 2005 is the best development tool for building data-driven web
applications. As part of the Visual Studio 2005 suite of tools, Microsoft is
introducing a new tool called Visual Web Developer (VWD) that is designed to
work with the current and next generation of ASP.NET. VWD provides powerful new
features for the web developer.................
One of the key goals of ASP.NET 2.0 is to ease the effort required to deploy,
manage, and operate ASP.NET web sites. To this end, ASP.NET 2.0 features a new
Configuration Management API that enables users to programmatically build
programs or scripts that create, read, and update configuration files such as
Web.config and machine.config.............