New code separation model coming in beta 2

Onion Blog

Syndication

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
Filed under:

Comments

Matt Milner wrote re: New code separation model coming in beta 2
on 11-17-2004 6:38 PM
To your point on how this partial class gets precompiled, I think the other "half" of this partial class is like the WinForms implementation where it will be a separate .cs or .vb file that probably hides behind the aspx file and actually gets compiled in at compile time (a show all files should bring it up under that aspx page). It is just the place holder for all of the old "do not edit this" regions of ASP.net 1.x. That's just my guess though.
andyBlog wrote Whidbey Beta2 change in code behind.
on 11-18-2004 4:54 AM
Whidbey Beta2 change in code behind.
Sergio Pereira wrote re: New code separation model coming in beta 2
on 11-18-2004 5:40 AM
All this seem very strange. Sometimes it feels like the ASP.NET team is just trying to find a use for partial types, and they are using it to hack the controls declarations away in a misteriuos place... the v1.x control declaration already looks like a hack in itself.
So, they tried to use a new tool to hide the ugly, misterious syntax, introducing undesired syntax changes, and now finding a way to restore the original syntax (base class declaration).
I don't have any problem with either way, just like I don't have any problem with the current way (protected member declarations for the controls). I just don't agree with ScottGu when he says that we don't need to understand the implementation... right. I for one need to understand to feel comfortable designing my classes.
Jeffrey Palermo wrote Whidbey: Code-beside going away - back to code-behind - level 200
on 11-18-2004 7:09 AM
Whidbey: Code-beside going away - back to code-behind - level 200
Sahil Malik wrote re: New code separation model coming in beta 2
on 11-18-2004 8:57 AM
Fritz this is fantastic, if you remember, I had asked you in dotnetrocks about "What do we do now that we can't inherit without succumbing to a royal pain". And your answer was "Try and find joy in the pain" (well not exact words, but you know what I mean).

I am SOO GLAD that this inheritance model came back. I am thrilled !!!

Now to all the code that I had written in the code-beside model .. urrghh !!
Sahil Malik wrote re: New code separation model coming in beta 2
on 11-18-2004 9:08 AM
Onion Blog wrote More details on code behind v2
on 01-18-2005 9:40 AM

Add a Comment

(required)  
(optional)
(required)  
Remember Me?