views:

91

answers:

2

I have an extension method which I can use from the .cs codebehind of an aspx page, but if I try to do it in a code block in the aspx, it can't find the extension method. Is there something I need to add to the page?

+5  A: 

You need to include the namespace containing the extension method at the top of the page, like this:

<%@ Import Namespace="Your.Namespace" %>

You can also include it globally in Web.config:

<pages>
    <namespaces>
        <add namespace="Your.Namespace" />
    </namespaces>
</pages>
SLaks
Thanks. I didn't realize I'd have to do that, because the extension method is in the same namespace as the code behind class.
Jeremy
+1  A: 

The appropriate using directive:

<%@ Import Namespace="NamespaceContainingTheStaticClass" %>

Or even better do it globally in web.config

<pages>
   <namespaces>
      <add namespace="NamespaceContainingTheStaticClass" />
   </namespaces>
</pages>
Darin Dimitrov