Template page in ASP. NET

Source: Internet
Author: User

Programmers who have used JavaStruts should know that Struts has a template tag. Although it is complicated to use, it brings a lot of convenience to a large number of page programs. However, there is no ready-made implementation available in ASP. NET, which is rarely discussed in China. In fact, we can rewrite the sender method to implement similar functions. The following is a base class template class used in my project.

1 using System;
2 using System. Web. UI;
3
4 namespace 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 attributes # region attributes
13 string pageTitle = "Title ";
14 string pageHeader = "<table cellspacing = '0' cellpadding = '0' width = '000000' height = '49' background = 'HTTP: // localhost // RepeaterDemo // Images/top_stripe1.gif 'border = '0'> "+
15 "<tr>" +
16 "<td valign = 'top'> </td> "+
17 "</tr>" +
18 "</table> ";
19 string pageScript;
20
21 string pageLeft = "Menu ";
22
23 string pageFooter = "<div align = 'center'> meil.cnblogs.com meil: Copyright: 2006 </div> ";
24
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 (@ "63 writer. Write (pageScript + @ "64
65 writer. Write (pageHeader );
66
67 writer. Write (@ "<table> <tr> <td width = '000000'>" + pageLeft + @ "</td> <td> ");
68
69 // second, the base class is allowed to render the HTML code and ASP. NET controls on 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> 77}
78}
79
80}

 

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.