Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build an ASP.NET web page template

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to build an ASP.NET web page template". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to build an ASP.NET web page template.

In a website, each page often has the same part, such as: header, footer, header displays site logo, navigation bar, etc., footer shows copyright and so on. If each page writes these contents directly, it will bring great difficulties to development and maintenance.

In ASP, we often use include include files to solve the problem. In ASP.NET, we use web page templates to solve the problem. The steps are very simple:

First create a master page (.master file).

Then create a content page and use it to "instantiate" the master.

Master page

Open Visual Web Developer and create a new .master file. You can see that the compilation instruction is Master, not Page. The most important control in the master page is ContentPlaceHolder, which will be controlled by the file referencing the master. In the following example, we use three ContentPlaceHolder.

<% @ Master Language= "C#"% > < script runat= "server" > < / script > < html xmlns= "http://www.w3.org/1999/xhtml" > < head runat=" server "> < title > Untitled Page < / title > < / head > < body > < form id= "form1" runat= "server" > < div > < asp:ContentPlaceHolder id= "m_header" runat= "server" > < asp:BulletedList ID= "nav" runat= "server" > < asp:ListItem Text= "Navigation 1" > < / asp:ListItem > < asp:ListItem Text= "Navigation 2" > < / asp:ListItem > < / asp:BulletedList > < / asp:ContentPlaceHolder > < asp:ContentPlaceHolder ID= "m_content" runat= "server" > < / asp:ContentPlaceHolder > < asp:ContentPlaceHolder ID= "m_footer" runat= "server" > < p > copyright < / p > < / asp:ContentPlaceHolder > < / div > < / form > < / body > < / html >

Content page

Open Visual Web Developer, create a new .aspx file, and delete everything except the compilation instruction.

Specify MasterPageFile and Title. MasterPageFile indicates which master file to use, and Title is equivalent to < title > < / title > in HTML.

Insert the Content control and specify the ContentPlaceHolderID in the Content control to indicate that you want to replace the contents of the ContentPlaceHolderID in the master with the contents of this Content. Note that there is no need to process every ContentPlaceHolder in the master file, and if there is no corresponding Content, ContentPlaceHolder uses what is indicated in the master file. The file code is as follows:

<% @ Page Language= "C#" MasterPageFile= "MasterPage1.master" Title= "Home"% > < asp:Content ID= "content" runat= "server" ContentPlaceHolderID= "m_content" > < p > here is the home page < / p > < / asp:Content > Thank you for your reading. This is the content of "how to create an ASP.NET Page template". After the study of this article, I believe that you have a deeper understanding of how to establish an ASP.NET web page template, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report