Masterpages: Introduction)

Source: Internet
Author: User

(for those who reference this translation, please specify the source)
Dudu blog has referenced the original, the original source http://authors.aspalliance.com/PaulWilson/Articles? Id = 13
now, vs2005 already contains masterpages controls

overview
the page template technology is available, it also supports the form Technology under runat = server, but masterpages is the only one by Microsoft ASP. the applications developed by the net group are stored in ASP. net. When talking about page templates, rob Howard, a design expert at Asp.net, said similar technologies will appear in the next Asp.net version. This article discusses masterpages demo instances released by Microsoft earlier. My next article improves this technology, provides functions supported during design.

What is masterpages?
Masterpages contains a set of server controls. You can download them from the control introduction on Microsoft's Asp.net website. It also contains a simple demo. Unlike other page template technologies, it uses controls instead of compiling and generating custom page base classes at the beginning. The designer can easily generate a user control for use as a template, mark it as "region", and add a "content" control Matching Region on the page containing the "controliner iner" control. Note anyCodeYou only need to use the masterpages control.

Generate a template
To generate a template, you must first generate an Asp.net user control that shares other pages and add it to the general page layout. Then, an identifier is provided in the page layout. The identifier must be defined by an individual page and identified by the region control with a unique ID. This ID will be used for matching later. As long as you like, you can add multiple contentregion controls and add common content controls without matching IDs.
Example 1: generate a template

<% @ control %>
<% @ register tagprefix = "MP" assembly = "masterpages"
namespace = "Microsoft. web. samples. masterpages "%>


masterpages


page header



default content

page footer



use this template
to use this template, you must first create an empty Asp.net page to delete all the code automatically generated by the wizard. Add the "contentcontainer" control and "content" Control of masterpages. The contentcontainer control contains the masterpagefile attribute. The content control has the ID attribute and matches the IDs of different region controls. One thing you only need to do is add the matched content control to contentcontainer. However, if you prefer to use the default content control, you can skip the Region Matching practice.
Example 2: Use this template

<% @ Page %> <% @ register tagprefix = "MP" assembly = "masterpages" namespace = "Microsoft. web. samples. masterpages "%> <MP: contentcontainer runat =" server "masterpagefile =" template. ascx "> <MP: Content ID =" mpheader "runat =" server "> Sample page </MP: content> <MP: content ID = "mpcontent" runat = "server"> real content </MP: content> </MP: contentcontainer>

Why use masterpages?
Why use matetrpages instead of another page template technology? First, what is the flexibility of this method, because it can automatically support multiple region, or use the optional region of the default content, with better encapsulation and high template reusability. It is also easier to use, because you only need to use the control implementation instead of writing code, it is more suitable for integrating into ASP. NET page-control model, allowing developers to free up the compilation of other non-Gui functional page base classes. Finally, it is likely to become the official method of ASP. NET templates in the future.

Masterpages Problems
Unfortunately, the current materpages is just a demo. This means that no features are supported at design time. You cannot drag and drop region and content controls like other controls. You must manually add them. Regions and content do not have visual L. You will also find that the namingcontainer technology brings flexibility, while also making the control Id like container: _ ctl0: Region: control. This control layout slows down.

Conclusion
Masterpages is the most flexible and easy to use Page Template technology. Since it is developed by Microsoft, it is likely to appear in ASP. NET in the future. In the initial demonstration, the design was not supported and the performance was poor. However, my next article will show you how to solve this problem, in addition, I will add the function of defining the default content region and default template files, and how to solve the previously annoying namingcontainer problem. Finally, on my homepage, you will find some examples of templates that can be selected.

Author bio
Paul Wilson is a software architect in Atlanta, currently with a medical device company. He specializes in Microsoft technologies, including. net, C #, ASP, SQL, COM +, and VB. HisWilsonwebformControl allows multiple forms and non-PostBack forms in ASP. NET. He is a Microsoft MVP in ASP. NET and is also recognized as an aspfriend'sAspace/aspelite. He is a moderator on Microsoft'sASP. NET forums, As well as one of the top posters. He is certified in. Net (mcad), as well as also holding the MCSD, mcdba, and MCSE. Please visit his website,Www.wilsondotnet.com, Or email himPaul@WilsonDotNet.com.


For the next article, see:Masterpages: Improved Version)

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.