A pagelet is an ASP+ page that is imported as a server control by another ASP+ page (or many other ASP+ pages. Pagelet controls provide an easy way to partition and reuse simple, common UI functionality across a Web application. Pagelets are not precompiled but, because all ASP+ pages are compiled when requested, they are compiled on demand and cached in server memory.
You create a pagelet by authoring an ASP+ page just like a regular page except that the pagelet does not include <html>
and <body>
elements around the content. Those elements are contained in the ASP+ page where the pagelet is inserted.
Important Pagelets that post events should not contain an HtmlForm control (a <form runat="server"></form>
element). Instead, the containing page should include one around the pagelet control tag.
The pagelet filename is subject to the same naming conventions as ASP+ page files. It is recommended that you use the .aspc file extension rather than .aspx so that your pagelets do not get compiled in the same way as a standard Web Form.
Defining a Pagelet
The following simple example shows how a pagelet could be used to encapsulate a navigation bar that remains constant on all pages in an application.
<%@ Page Description=”A Simple Pagelet Control” %> <table> <tr><td>< a href="news.aspx">news</a></td></tr> <tr><td>< a href="weather.aspx">weather</a></td></tr> <tr><td>< a href="sports.aspx">sports</a></td></tr> </table>
Inserting a Pagelet
To insert a pagelet in another page, use a @ Register directive that specifies:
Then, use a custom server control tag in the desired place on the containing page. For example, if the pagelet shown above was saved as navigation.aspc, a containing page would import the pagelet with the following syntax:
<%@ Page Description="A Sample Page Consuming a Pagelet" %> <%@ Register TagPrefix="PageletCtrl" TagName="NavBar" src="navigation.aspc" %> <html> <body> < UserCtrl:NavBar id="MyNavBar" runat="server" /> </body> </html>
See Also