Programmers who have used JavaStruts should know that there is a template tag in Struts. Although it is more complicated to use, it brings a lot of convenience to programs with a large number of pages. However, there is no ready-made implementation available in ASP.NET, and there is little discussion in this regard in China. In fact, we can also achieve similar functions by rewriting the sender method. Below is a base template class used in my project.
1using System;
2using System.Web.UI;
3
4namespace RepeaterDemo.Web.PageTemplate
5{
6 /**//// <summary>
7 /// WebPageTmplate page template base class.
8 /// </summary>
9 public class WebPageTmplate:System.Web.UI.Page
10 {
11
12 properties#region properties
13 string pageTitle="Title";
14 string pageHeader= "<table cellspacing='0' cellpadding='0' width='100%' height='49' background='' border='0'>" +
15 "<tr>" +
16 " <td valign='top'><img alt='' src='' border='0'></td>" +
17 " </tr>" +
18 "</table>" ;
19 string pageScript;
20
21 string pageLeft=" Menu";
twenty two
23 string pageFooter="<div align='center'>meil.cnblogs.com meil Copyright 2006</div>";
twenty four
25
26 public string PageTitle
27 {
28 set {pageTitle=value;}
29 get {return pageTitle;}
30}
31
32 public string PageHeader
33 {
34 set {pageHeader=value;}
35 get {return pageHeader;}
36}
37
38 public string PageScript
39 {
40 set {pageScript=value;}
41 get {return pageScript;}
42 }
43
44 public string PageLeft
45 {
46 set {pageLeft=value;}
47 get {return pageLeft;}
48 }
49
50 public string PageFooter
51 {
52 set {pageFooter=value;}
53 get {return pageFooter;}
54 }
55
56 #endregion
57
58 protected override void Render(HtmlTextWriter writer)
59 {
60
61
62 writer.Write(@"<html><head><title>" + pageTitle + @"</title>");
63 writer.Write(pageScript + @"</head><body>");
64
65 writer.Write(pageHeader);
66
67 writer.Write(@"<table><tr><td width='200'> " + pageLeft + @"</td><td>");
68
69 // Secondly, the base class is allowed to render the HTML code and ASP.NET controls in the ASPX page
70 base.Render(writer);
71
72 writer.Write("</td></tr></table>");
73
74 writer.Write(@"<div align='cnter'>" + pageFooter + @"</div>");
75
76 writer.Write(@"</body></html>");
77 }
78 }
79
80}
81
82
http://meil.cnblogs.com/archive/2006/06/22/432709.html