Home arrow ASP.NET arrow Page 4 - Easy ASP.NET Page Templates
ASP.NET

Easy ASP.NET Page Templates


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!

Author Info:
By: John Rebbeck
Rating: 4 stars4 stars4 stars4 stars4 stars / 259
December 29, 2002
TABLE OF CONTENTS:
  1. · Easy ASP.NET Page Templates
  2. · ASP.NET Pages
  3. · Implementing Multiple Editable Regions
  4. · JavaScript
  5. · Conclusion

print this article
SEARCH DEVARTICLES

Easy ASP.NET Page Templates - JavaScript
(Page 4 of 5 )

When adding site-wide JavaScript code, I suggest that you use an external file because it is easier to implement and provides additional performance benefits. To do this you just add the <script> tag that references the JavaScript file between the <head> tags of the page by adding it in the Render method.

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>

<script language=”javascript”>
//...place some JavaScript code here.
</script>

<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.

Advantages:
  • 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.
Disadvantages:
  • 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.

blog comments powered by Disqus
ASP.NET ARTICLES

- How Caching Means More Ca-ching, Part 2
- How Caching Means More Ca-ching, Part 1
- Reading a Delimited File Using ASP.Net and V...
- What is .Net and Where is ASP.NET?
- An Object Driven Interface with .Net
- Create Your Own Guestbook In ASP.NET
- HTTP File Download Without User Interaction ...
- Dynamically Using Methods in ASP.NET
- Changing the Page Size Interactively in a Da...
- XML Serialization in ASP.NET
- Using Objects in ASP.NET: Part 1/2
- IE Web Controls in VB.NET
- Class Frameworks in VB .NET
- Cryptographic Objects in C#: Part 1
- Sample Chapter: Pure ASP.Net

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials