How can you create event handling code in ASP.NET and share it between controls on multiple pages?
For example, two pages with
<asp:Repeater runat="server" OnItemCreated="NavigationItemCreated">
Instead of copying it for each page, I tried to put it in a class accessible for both pages
<asp:Repeater runat="server" OnItemCreated="MyHelper.NavigationItemCreated">
The class is as follows:
public class MyHelper { public static void NavigationItemCreated(object sender, RepeaterItemEventArgs e) { } public static string MyProperty { get; set; } }
However, I get an error when I try to execute (happens with or without static ):
Compiler error message: CS1061: "ASP.page_default_aspx" does not contain a definition for "MyHelper" and there is no extension method "MyHelper" that accepts the first argument of type "ASP.page_default_aspx" (do you miss the use directive or assembly reference? )
I can still access MyProperty with <%# MyHelper.MyProperty %> , so MyHelper can be used by the page, not by event handlers.
Update:
Made the class and event handling code static, and it also doesn't work, doesn't put it in its own namespace and uses MyNamespace.MyHelper.NavigationItemCreated
source share