Please let other users know how useful this tip is by rating it below. Do you have a tip or code of your own you'd
like to share? Submit it here.
Pagelet Controls, also known as User Controls, are Web Forms that are modified to be used as Server Controls. In ASP 3.0, we used to include files -- this was really not the best solution for resuability. Luckily, ASP.NET provides these new powerful Pagelet Controls.
Pagelet Controls can be used in more than one hosting page and more than once in the same hosting page. Pagelet controls have the extension *.ascx. You need a hosting page to use this control. To use this control in a hosting page, you have to register it using the <%Register ...... %> directive. Commonly, Pagelet Controls could be used as header or footer for the page.
In the example below, Header.ascx is the Pagelet Control, while the hosting page is Header.aspx. Note: Header.ascx (Pagelet Control) has been registered using the register tag; also note the usage of Tagprefix, Tagname and the src attributes.
Header.ascx <script language="vb" runat="server"> public property textBoxValue as string get return mytext.text end get set mytext.text = value end set end property </script> <center> <br> <asp:label id="mylbl" text="THIS IS THE HEADER PAGELET CONTROL" borderstyle=2 forecolor="red" runat="server" /> <br><br> <asp:textbox id="mytext" runat="server" /> <br> </center> Header.aspx <%@ register tagprefix="PageLet" TagName="Header" src="Header.ascx" %> <form runat="server"> <pagelet:header id="myPagelet" textboxvalue="pagelet control attribute" runat="server" /> <br> <br> <asp:button id="button1" text="button 1" runat="server" /> <asp:label id="lbl" text="label and button in the aspx file and the Pagelet control is used here" runat="server" />
Save these files to the Web server's (IIS) wwwroot folder and run: http://localhost/header.aspx.