Create a dynamic ASP page with a template

Source: Internet
Author: User
Tags html page html tags table name touch access database
For the template, I think you may have some concepts, in Word, a lot of templates, design the approximate layout, you just fill in your own words that placeholder characters. The template here is probably the meaning, the relatively stable part of the page is fixed, the other part of the root of the different situation in the input of different content. In fact, there are templates in the Dreamweaver function, but the static, can only manually fill the content, and here is the dynamic automatic content fill.

First, let me explain why I use the template file. Sometimes, templates can bring you a more complete concept of Web page functionality and layout. When you see the template format for Word, you know what the final layout looks like, and here it is. For example, you can keep ASP statements and use different templates to create different page styles. That way, you don't have to write different ASP pages for each different style of Web page, which obviously saves us a lot of time and effort.

Also, template files can make it easier for you to browse the page code without worrying about your confusing ASP and HTML mix. You can just focus on the HTML and do not have to manage the ASP at all. Then there is, the touch board is very simple, you absolutely will soon be able to understand the handle. In this article, you will use a database-a very broad list of employees. Includes employee ID, name, photo, and work summary and photo footnotes. The following is the structure of this Access database:

FileName-Mydatabase.mdb

Table Name-Employees

Id

Automatic count (Autonumber)

FullName

Text-up to 100 characters

Picurl

Text-up to 255 characters

Duties

Annotation type

Piccaption

Text-up to 50 characters

A very simple database, right. Of course you can expand it as required, and that's your own business. I assume that you know the basics of the database so that I don't have to spend too much ink on it, but the code here is very simple, as long as you know something basic, you can read it. Once we have established the database, we can start creating the template file. This file is the skeleton of each page. I didn't use the form, that was a bit of a hassle, and I was lazy and:-), and I didn't have to add, tag, because it was added to the ASP page. So in the end, it looks like this:

< img src= "%img%" align= "left" >< p>full Name: < b>%name% </b>
< br>description of Duties: < br>%duties%
< Br>this picture is taken:%date%
< br>< br>
Employee ID:%empid%

That's it! This is a simple template. Save it as template.tmp, and it will be referenced in the following ASP page. Note that we can add a variety of HTML tags to the template, you can completely define the structure and style of the page in the touch version, just like writing a Web page, just to mark the key points--notice the things around the%? That's the essence of the template. You may have noticed that the% of those% are corresponding to the fields in the database. Look at the following ASP code, how to read the template and database files, rub them together, and then output the HTML page we want.
< html>
< head>
< title><%=rstemp ("FullName")%></title>
< body>

</body>


That's all the code, it's simple, isn't it? It simply opens the template file, reads each row sequentially, and then replaces those%img%,%name% tags in the stencil with the actual field values that are read in the punch database. Also, it interprets the carriage return in the large text in the "duties" field as an HTML carriage return < Br&gt, so that it doesn't disrupt the entire layout format. What do you think? It's easy to handle. The template in some applications really can play wonders, save time and effort. In theory, you can also modify this code to read and write text using FileSystemObject so that the data is not necessarily stored in the database. In some applications, such as instant press releases, this may be more convenient.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.