Anders Norås’ posted an interesting article about the intent of code-behind. He says doing:
<TITLE><%# GetResourceString(“PageTitle”) %></TITLE> |
is better than doing this:
public class MyPage : System.Web.UI.Page { |
On my team, there is much discussion about putting any function call int the aspx file whatsoever, so this strikes me as an interesting take. Honestly, I do a mixture of both, but in the above case, I do exactly what the second code snippet does. I do all programmatic manipulation in my code-behind file. I try to have only markup in my aspx and ascx files.
In v2.0, I imagine I would do the following:
public partial class MyPage{ |
And I really don’t agree that setting content in code is a bad thing to do. If I was forbidden to do it, I would not be a very effective programmer at all. For instance, I use a base page class to set the title of every page in my application. There is no way that I am going to put a function call in the markup of every aspx just to set the title when I can do with one call in my base page. That just doesn’t make sense.
Anders, your method works well for mostly declarative pages, but I disagree with you. I prefer the code method.