A pagelet is an ASP+ page containing HTML tags and executable code. 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.
The pagelet file name is subject to the same naming conventions as ASP+ page files. You can use the .aspx extension or an .aspc extension if you want to distinguish pagelet control files from regular ASP+ files.
Differences Between a Page and a Pagelet
Because pagelets are included in existing pages, they do not contain <head>, <body>, or <form> tags. Those tags are included in the ASP+ page that uses the pagelet control.
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 User 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>
Implementing the Pagelet
To insert this pagelet control in another page, use an @ Register directive that specifies the source (file name) of the control and a friendly tagprefix:tagname pair that is used to declare an instance of the control on the containing page. Then a control tag with the attribute runat=server is placed in the desired spot on the containing page.
For example, if the pagelet control above was saved as navigation.aspc, a page would use it like this:
<%@ Page Description="Sample ASP+ Page Consuming a Pagelet Control" %> <%@ Register TagPrefix="UserCtl" TagName="NavBar" src="navigation.aspc" %> <html> <body> < UserCtl:NavBar id="MyNavBar" runat="server" /> </body> </html>
For a more complex pagelet control example, see the example in Using Pagelet Controls.