I have spent a lot of time talking about all sorts of new features in .NET 2.0, but I have never really spent any time talking about the basics of how the page itself has changed. I always assumed it was kind of obvious, but it really isn't if no one has told you.
The first thing you need to know about is the concept of the partial class. I may have talked about this at some point. Basically, it allows multiple files to come together to create one class when compiled.
Second, you need to now understand that your markup that you put in your .aspx or .ascx is truly code. It can be compiled as such. When you drop any of these new controls onto a page in the designer, that control is declared. It does not (and cannot) have a line in the code behind file declaring it (i.e.: System.Web.UI.WebControls.TextBox PickupLocationTextBox). This means there is no more going into the designer of your markup and trying to get it to autogenerate those declarations in the code behind for you.
Out of the box, here is what the markup of a page looks like when you create it.
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Blah.aspx.cs" Inherits="Blah" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body></html>
Notice it automatically sets the doctype to a flavor of xhtml. The codebehind is even simpler.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Blah : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Notice that there are not any hidden regions containing OnInit and event bindings. All events on controls are declared in the markup now, not by adding a line in the OnInit method.
Those of you who have already worked with it a bit probably already understand this, but if you haven't worked with ASP.NET 2.0 at all yet, this information will prove useful.
Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=77