It's a good idea to keep highly reused code seperate from your page content. In this article John shows us everything we need to know to get started with templates in our ASP.NET pages... the easy way!
When adding a page specific script you can just write the script between (or even inside) the controls on the page and it will be rendered on the page along with everything else:
<%@Page ... >
<asp:Panel ID=”LeftCol”> ... </asp:Panel>
<asp:Panel ID=”Body”> ... </asp:Panel>
<asp:Panel ID=”RightCol”> ... </asp:Panel>
Heirarchial Page Classes In some web sites where different sections of the site have different templates including shops, forums, admin, etc, it may be beneficial to not just have 1 base Page template but to have a tree of them.
You should have 1 truly base Page class which is derived from to make more specific templates, then, if necessary, they can even be derived from again to make even more specific base page classes.
A base Page class tree may look something like the following:
When Should Page Templates be Used? Any web site with more than one page that has items consistent on each of them such as headers, footers, menus, session summary, shopping cart summary, etc, or even common functionality such as retrieving a user’s Username and displaying it should use templates.
Development is simplified because every page already has a base to work from reducing the need to copy and paste common page features such as headers, menus, footers from other pages.
Maintenance is simplified because a change to a common page feature can be made in a single place with all pages on the site reflecting these changes instantly.
User friendliness is enhanced because every page is consistent with every other page making it easier to locate menus etc, on the page.
Page templates can be added to a page simply by making each page inherit the custom Page class.
While other template techniques exist, this is one of the most effective and most powerful while still remaining extremely simple to use.
The base page template uses code to design and render some consistent controls which is slightly more difficult and time-consuming than using the HTML designer.
When writing in the HTML section of the designer, there is no assistance from VS.NET's HTML IntelliSense because you are not writing inside the <body> tag.