Another way (other than my other post) would be to create your logic
in a user control, add your .ascx and code behind to the
/_controltemplates/ VDIR, then insert your register tag in your .aspx
page. We've done this a few times for some custom code we needed to
put into the layout.
Like so...
In the head...
<%@ Register TagPrefix="userControls" TagName="ctrlSearch"
src="~/_controlTemplates/ctrlSearch.ascx" %>
Where you want your control...
<userControls:ctrlSearch runat="server"/>
You could always compile to .dll and put that in the GAC too, but
that's a little bit more complicated. The above is process is IMHO
easier.
LMK if you have questions,