Where's the code-behind for sharepoint aspx pages?
asp.net, c#, sharepoint-2010, visual-studio-2010
Solution
In SharePoint, you can have a code-behind class, but it needs to be in an assembly, not in an aspx.cs code-behind file.
Using Visual Studio 2010, the Page directive for your aspx page would look something like this:
<%@ Page
Language="C#"
DynamicMasterPageFile="~masterurl/default.master"
Inherits="MyNamspace.MyPage, $SharePoint.Project.AssemblyFullName$"
%>
You can then create a `MyNamspace.MyPage` class and do everything you would do in a regular code-behind file.
If you take a look at the out of the box aspx pages in the 14 hive\TEMPLATE\LAYOUTS directory, you will see, while some pages have inline code (which is allowed in layouts), almost every page inherits from a class in one of the SharePoint assemblies.
Problem
No doubt I'm missing something very obvious here - but I'm new to sharepoint so please bear with me. I've successfully added a master page, created a content type and have created an aspx page for my custom content type - but I can't find its cs file!? Is there another way in which code-behind is implemented in sharepoint solutions? It seems to be similar when creating controls. I'm used to standard asp .net c# web application development were all of the aspx pages come with the code-behind files 'as standard.' Thanks.