Foreword
In previous (perhaps now), when we are doing a web project, some common files are often used, such as the top of the entire page (header), left (navigation), bottom (foot), etc. HTML, ASP and other documents, even so, we also need to do a good frame for these files (usually with TABLE?! There are not a few Divs) to get a complete page with a combination (include). The combination of these shared documents, here assumes defining it into a template (although the true meaning of the template may be much more than this). Even so, when the entire framework changes in our project, we must not modify each of the tops that are originally used by some HTML tags that have passed Table and so on, and such a job can be used by Ctrl C and Ctrl V. Completed, but the workload is also huge, time consuming.
development of
In ASP.NET, use is an object-oriented development mode, which can be so understanding - each page is a Class from SystemWeb.ui.page, which provides us with some cache, indicating, response , Request and other services (saying that it is a way). Is it better to solve the object-oriented method? Of course, the answer is affirmative.
achieve
I remember that there is a famous saying "Any problem can be implemented by joining a middle layer", which is a very simple example, and we often use the Façade mode to reduce the system's coupling, and why should we use design mode? Mainly used to reduce coupling improvement multiplexing.
From all the ASPX pages inherited from systemweb.ui.page, we only need to join a layer between ASPX and SystemWeb.ui.page, write a layer of our own Class to make the problem simple In the .NET framework, allow the user to customize the HTML code (this can be referred to the web user controls) so that the prototype of the problem will come out, see the figure below.
The "Custom Class" in the figure is equivalent to one of the intermediate layers we join, the custom class inherits the base class of System.Web.ui.page, below the category code:
Pagebase.cs
Public class Pagebase: System.Web.ui.page
{
Public string pagetitle = "Test Template";
Protected Override Void Render (System.Web.ui.htmlTextWriter Writer)
{
Writer.write (@ "
Writer.write (@ "
Home b> font> td> | advertunch td>
TR> | |
navigation p> Find contacts P> td> | td> |
"); Base.render (Writer); Writer.write (@ " td> tr> |
Foot foot td> tr> table> body> < / html> ");
} } The above PageBase.cs is our customty, so we can inherit this class directly in other ASPX pages, not system.Web.ui.page, below the code of index.aspx and newcontact.aspx (I contain index.aspx.cs and newcontact.aspx.cs: INDEX.ASPX <% @ Page language = "c #" codebehind = "index.aspx.cs" autoeventwireup = "false" inherits = "wab.index"%> |