How to use extensions and utility methods in markup?

asp.net, extension-methods, markup

Solution

<%@ Import Namespace="Common.Extensions" %>

I believe you can do that for all your markups in the web.config.

Problem

Ok. This is probably a really stupid question, but I'm going to ask it anyway... How can I use extensions and utility methods in my ASP.Net markup? For example, (say) I have a DateTime extension method called "ToExampleString()" (contained in the DateTimeExtensions class in my Common.Extensions project) and I want to use it in my markup in the ListView's ItemTemplate: ``` <ItemTemplate> <span><%# ((DateTime)Eval("DateStarted")).ToExampleString() %></span> </ItemTemplate> ``` I'm getting the following error: 'System.DateTime' does not contain a definition for 'ToExampleString' and no extension method 'ToExampleString' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?) The page simply can't see the extensions method. Similarly, how do I make my page's markup aware of a utility class: ``` <span><%# ExampleUtility.ProcessDate(Eval("DateStarted") %></span> ``` What steps do I need to take to make this stuff work? I assume I'm overlooking something stupidly obvious? Thanks

Original source