ASP.Net Headers/Templates
Found a good article on how to use "old fashioned" include style headers and templates with .Net. Unlike many of the "template" engine for .Net this one is overly simple and works like the old ASP (and PHP for that matter) includes.
Compliments of John Timney:
Traditional #include is not really a good option for the OO nature of
asp.net. The correct approach is to use user controls, but they can be very
simple to implement.
Add this line to the top of your aspx page:
includeme.ascx is the equivalent of the old include file with your HTML
etc, in my case it is a navigation menu
Code: |
< %@ Register TagPrefix="myProject" TagName="includedthing" Src="includeme.ascx" %> |
Then to position the include file in the page, add the line below to your ASPX
page where you want it positioned
Code: |
<myproject :includedthing ID="myfirstinclude" runat="server" /> |
^ Note in the above tag myProject:includething reference the TagPrefix and TagName from the ascx declaration (the line with Src=).
* If you are using the VS IDE you can simply drag and drop the .ascx file on your page where it should be included.