您的位置:首页 > 编程语言 > ASP

ASP.NET 2.0 Developers Overview

2004-09-14 17:35 393 查看
Introduction

ASP.NET 2.0 has more improvements, like ASP to ASP.NET 1.x improvements; though the learning curve require is not steep as the one needed to migrate from ASP to ASP.NET 1.x. The newer version is promising to give more productivity, flexibility, performance, scalability, security, administration and much more new features. You can add custom features to meet your own requirements and build your applications more quickly then ever before, with less code and effort. Here we go to see some of the new cool features available in 2.0.

Features of Page Framework

As an architect you would like to maintain a consistent look across all pages in your application. For example you’ll need to include a header and footer in your pages. You have to depend on user controls or include files, to design such common interface elements.
Though, it seems to be simple approach, some problems are there as follows.

All pages should contain reference to appropriate user controls.

Html Tags can span, but could be mismatched while spread across files.

Sever control tag cannot span multiple files; you have to close it in the same user control.

Editing the layouts or templates of the pages could lead to confusions and become difficult.

ASP.NET 2.0 addresses all the above problems with the Master Pages feature – “a Visual Inheritance”.

What is it actually?
A page, allows defining flexible and reusable templates. A page, allows you to avoid creating each new page of your application from the scratch. A master page has .master extension and @Master directive instead of @Page directive.

How to work with it?

Working with master pages involves the following steps: Add a master page template from Add New Item dialog box. Customize it with your requirements. Add content pages add reference to your master page.
Let us go further deep into that. When you add a master page into your application, as webform, it will have HTML elements such as <html>, <head>, <body> and <form>. And it will have a <asp:contentplaceholder> control, a new control in this version. The new control is used to place content into content pages which are referencing this master page.
In addition you can have server controls, event handlers and other markups. The HTML source of a new master page will look similar to this:

<%@ master language="C#" %>
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">

<asp:contentplaceholder id="ContentPlaceHolder1" runat="server"> </asp:contentplaceholder>
</form>
</body>
</html>

The @page directive of the content pages will have references to the master page as shown below.
<%@ page language="C#" masterPageFile="~/Jerome.Master" title="Sample Page"%>.
The <asp:content> control in the content page, will provide content for ContentPlaceHolder in the master page.

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="server">
</asp:Content>



Some Tips

When you use master pages, event handler hierarchy will be starting from content page handlers then master page handlers. This control hierarchy will be generated during runtime when ASP.NET combines content page and master page into a single object.
You can have multiple master pages into your application. Further, a master page itself can have reference to other master page, using its @master directive’s master attribute. You can override the Master content in you content pages.

<%@ master master="~/Temp.master" language="C#" %>

Instead of referencing a master page into each page’s @page directive, you can have a default master page for all the pages in your application. You can achieve this using <pages> element of your applications web.config file.
<pages master=”~/Jerome.master” />

Any content placed within a ContentPlaceHolder will become content for its pages. Even though, as per your page specific needs, you can override the Master content in your content pages.

Conclusion

The addition of Master pages in ASP.NET 2.0 will enable you to create Consistent page layout, shared UI and Code elements in more efficient ways. Definitely Master pages will reduce the development time in terms of effort and in no. of lines of codes, noticeably.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: