New Code-Behind Model in ASP.NET 2.0

          

ASP.NET 2.0


ASP.NET 2.0 Features
Developer Productivity
            Master Pages
            New Code-Behind Model in ASP.NET 2.0
            Creating & Sharing Reusable Components 
            New ASP.NET 2.0 Controls
                       Data Controls
                       Security Controls
                       Other New Controls
                       Validation Groups
            Themes
            Web Parts Framework
            Visual Studio 2005 Improvements
Administration and Management
Speed and Performance
            Caching Feature
New Code-Behind Model in ASP.NET 2.0 

Professional ASP.NET 2.0 Databases

This excerpt from Professional ASP.NET 2.0 Databases   by Thiru Thangarathinam, is printed with permission from
Wrox Publication.
<<Previous  Next>>

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” %>
<html>
<body>
<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”>
</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.

<<Previous  Next>>



Write your comment - Share Knowledge and Experience


More Related links  

.NET Code Security

This includes explanation of code security, Principal object, declarative and imperative security, role-based security, code access security and code group.

.NET Assembly 

This article explains .Net assembly, private and shared assembly, satellite assemblies, resource-only assembly, ResourceManager class, strong name, global assembly cache.

.NET Debug & Trace

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 Web Parts Framework

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 Improvements

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

ASP.NET 2.0 Administration and Management

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

 

Latest placement tests
Latest links
 
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring