SharePoint MOSS 2007: Adding Custom Code - An Introduction
Sadly, code behind pages are all blocked by default in SharePoint. You dont have direct access to any of the .CS code behind pages via SharePoint Designer and you have no way of building an .ASCX user control (that I know of anyway). So even though you can modify HTML and drop in existing controls to your page templates and custom .ASPX pages, our hands are tied when it comes to building additional custom functionality.
What we can do is package our custom functionality into a Web Part or a new Server Control, which we can then expose to SharePoint for use in our pages. Both are built in VS, then compiled down to a .DLL that we'll need to install on the SharePoint server. The trick is knowing when to use a Server Control and when to use a Web Part.
Server Controls are more what traditional ASP.NET developers are accustom to implementing in .ASPX pages. Server controls deployed to the SharePoint server become available in SharePoint Designer for use in custom .ASPX pages and SharePoint Page Templates (and masterpages). Server Controls can handle just about any kind of custom functionality you might need and also support design time functionality that your SharePoint Designer people might find useful. I'm a big fan of server controls and use them whenever possible.
Web Parts allow for custom code within a provisioned page ... as in a page created via the site actions menu and there afterward controlled by SharePoint. These pages are typically stored as data in the Pages library, where you have no access to the .ASPX source code at all. Since we cant even drop a Server Control into a provisioned page, the only option we have left is to drop a Web Part into an existing Web Part Zone to get the functionality we need in a particular page instance.
With all that in mind, lets take a look at building a simple Server Control to add some custom functionality to the default out of the box SharePoint master page... (coming soon!)