I just spent some time tracking down a bizarre bug in Venus (ASP.NET 2.0). A bit of background: when you’re programming with templated controls like a DataList, you often use databinding expressions to bind fields of the current row to a control. For example:
<asp:DataList runat="server">
<itemtemplate>
<asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem, "field") %>'/>
</itemtemplate>
</asp:DataList>
The databinding expression, DataBinder.Eval(Container.DataItem, "field") is rather verbose, however. In ASP.NET 2.0, this expression is simplified to: Eval("field"). Much, better, right?
Now let’s look at how this is implemented. There is a new method on the Page class called Eval. Note that they put this helper method in the Page class …
Tonight, I was moving some code to a user control. All of a sudden, my Eval(...) expressions were blowing up with compiler errors. This, of course, is due to the fact that Eval(...) was added to only the Page class, and not to a class that both UserControl and Page derive from. Ooops.
Moral of the story: when using the Alpha bits, you’ll need to revert to the old-school DataBinder.Eval() syntax when databinding in a user control.
1 archived reader comment
Cengiz (2004-02-07)
so good:)