[MasterPages Practical Tips] Implement Web Forms Templates using MasterPages

zhaozj2021-02-16  81

If you are a web developer, face a large number of pages containing duplicate content, you must use the "template" to define the public part of the web page, and each page only needs to complete its unique content, generate the final page through the template .

Familiar with Dreamweaver web developers will like the template feature. But when we convert to the ASP.NET platform, it has to use a Microsoft's development environment that can only be considered a text editor (of course, this should be a perfect text editor), Microsoft is only in terms of graphical web design. Can be an outer country. Despite this, even without the graphical design interface you have obtained, Microsoft and other open source sides will provide us with a wealth of web form front-end controls. The masterpages can be said to be the most useful because it implements template feature in Dreamweaver, and with the support of the ASP.NET framework, using templates becomes easier, we can even add a lot of features to your template.

Implement Web Form Templates with MasterPages

Define template control

If our form layout is divided into upper and lower three parts, the middle part is a specific content area, then the final template content can be like this:

<% @ Register tagprefix = "mp" namespace = "microsoft.web.samples.masterpages" assembly = "masterpages"%>

Header
Field content < / TD>
Footer

1. Each masterpage template is a user control userControl, which can add a UserControl from the Visual Studio .NET environment. The user control of this example I was named "template.ascx" and put it under the root path of the web project.

2. There is such a line in the head of the HTML source code of UserControl: <% @ register tagprefix = "mp" namespace = "microsoft.web.samples.masterpages" assembly = "masterpages"%> This is a customized for the page Tab tags, with this tag, to use the various controls provided by MasterPages.

3, for the common part of the template design, these contents and ordinary HTML pages, the ASP.NET web form does not have any difference, if your web uses other userControl, and these UserControl is also public, then you can also be here Add in the template. In short, writing a template control is nothing difference with a web form. What we have to do is just the public content in the window, remove specific content. 4, in the location of the specific content in the web form, use

Control tag is replaced. In this example, RegconTent is an area of ​​the form specific content, each of which will be filled in its own content.

Use templates in the form

If you use the template example you just given, the HTML source code for the form is as follows:

<% @ language = "c #" debug = "true" trace = "false"%> <% @ register tagprefix = "mp" namespace = "Microsoft.Web.SampleMples.masterpages" assembly = "masterpages"%> Form content test

1. Like template controls, you must first register before using MasterPages before you first register.

2, add an MP: ContentContainer control in the form, three properties in the example: runat = "server" - this is the property that must be available in all web controls; masterpagefile = "~ / template.ascx" - - Tell the ContentContainer control, the template control used by this form is the template.ascx file under the web root path; ID = "test" - this property is not necessary, but if not or in all forms using this template This ID has a repetition, in the form of the form, we will not see the visual results of the form, but only display a ContentContainer control tag.

3, in

Join

, That is, the content of the form itself, its ID must correspond to the Region defined in the template. In this example, there is only one content - regontent - it corresponds to the region of the ID in the template.

Now, templates and forms can work normally. The results they generate are equivalent to such a form:

<% @ language = "c #" debug = "true" trace = "false"%>

< TD> Header
Form Content Test
Foot In "MasterPages Practical Skills" Next, you can understand the MasterPages-based template front-end control skills.

I hope to help you, thank you!

转载请注明原文地址:https://www.9cbs.com/read-11724.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.041, SQL: 9