Separate ASP From HTML

By Robbe D. Morris

Printer Friendly Version

Robbe Morris
Robbe & Melisa Morris
Active Server Pages provides a truly dynamic and easy way to create web sites.  However, one of its downfalls is that it doesn't really fit into the "separate the code from the content" methodology now promoted by most IT analysts.  Or does it?
Well, sort of...Those of you who have worked with Microsoft's long forgotten web class technology understood the advantages of using HTML templates from within your web class COM object.   However, the overhead that comes with using the web class runtime was unacceptable.   So, what's a developer to do?   Here's a real scaled down version of how to write an ASP page along with its corresponding HTML page and merge them together at runtime bringing the values captured/populated in ASP into the appropriate HTML controls/areas.  Beware, that this methodology does come with a cost in performance.  Used wisely, it can be a great benefit for pages that have considerable HTML complexities and only a few places for ASP variables.  Over used, and performance could suffer noticeably...


The code for test.asp is one the left and test.htm on the right.   Copy/Paste them into your own files and try running them (if you are running IIS):
It's not rocket science I know.   All I did was populate the HTML page with ASP tags of variable names that either contained specific form values or entire sections of HTML such as in lists.   However, we now have the ability to sit down with our HTML/UI interface team, decide on the variable/tag names and what they should contain.   They can write the pretty stuff while us real developers do what we get paid to do.   Write solid code!!!

Robbe has been a Microsoft MVP in C# since 2004.  He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.