Brock Allen alerted me to a change in the upcoming beta 2 release of ASP.NET 2.0 that affects the way code separation is implemented. Brian Goldfarb (a PM in the Web Platform and Tools division) has a post on the changes
here.
The change boils down to this - the class you define in your separate code file is no longer merged as a partial class with the .aspx-generated class definition, but rather with another intermediate partial class generated for you that contains protected member variable declarations of server side controls. Interestingly, it's no longer code-beside (a term that Microsoft never endorsed anyway) but really code-up-to-the-left-and-adjacent-to :) Perhaps we should call it code-diagonal...
Syntactically, here's what the change looks like. In beta1 you created a partial class and referenced it in your Page directive like so:
<%@ Page compilewith="mypage.cs" classname="mypage" %>
where mypage.cs looks something like:
public partial class mypage
{
//...
}
this changes in beta2 to the following:
<%@ Page inherits="mypage" codefile="mypage.cs" %>
where mypage.cs now looks something like:
public partial class mypage : System.Web.UI.Page
{
//...
}
Yes, you read that right - the 'inherits' keyword is back, and you are back to authoring the base class for your .aspx-generated class definition again. The difference between this and 1.1 is that you no longer have to declare protected/public member variables whose names match the ids of the controls in the .aspx file. This is apparently done in another intermediate base class that is created as a partial class and combined with your partial class declaration to give you access to the controls in the same way you do in the beta 1 release.
One thing this remedies immediately is something I wrote about in an earlier
post, which is the fact the in the beta 1 release you had resort to using
both the Inherits and CompileWith attributes to specify an alternate base class besides Page. Now you can do so easily because you are in control of specifying the base class, not your ghostly partial partner class.
One of the claims they are making about this change, is that it allows you to create pre-compiled assemblies that contain your code-separation classes which you can then deploy along with your declarative .aspx files so people can make changes to the HTML layout in a deployed site without having to deploy the source as well (the only two options in beta1). It's not clear to me how this is going to work, since the class you are writing is still a partial class that must be joined at the hip with this new intermediate partial class generated as part of the .aspx request processing, and the last time I checked, partial classes still have to be compiled together (not across assemblies). I look forward to seeing the beta 2 release to see how this works, but if anyone has any insight into how they achieve this in the meantime, please post a comment.
Posted
Nov 17 2004, 12:37 PM
by
fritz-onion