As Jason already answered, also put "CodeFile = anycodefile.cs" in the page directive.
<@Page ... Inherits="MyNamespace.MyCustomPage" CodeFile="MyCustomPage.cs">
If your page has a code file, use the CodeFile attribute. Otherwise, put the assembly containing the code behind the class in the bin folder and use inheritance. The class should be based on a web page or user control and should be publicly available.
SharePoint Newbie
source share