Problem solve Get help with specific problems with your technologies, process and projects.

Pagelet Controls

Pagelet Controls, also known as User Controls, are Web Forms that are modified to be used as Server Controls.

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.


<script language="vb" runat="server">
      public property textBoxValue as string
               return mytext.text
         end get
              mytext.text = value
         end set
     end property
<asp:label id="mylbl" text="THIS IS THE HEADER PAGELET CONTROL" 
borderstyle=2 forecolor="red" runat="server" />
<asp:textbox id="mytext" runat="server" />


<%@ register tagprefix="PageLet" TagName="Header" src="Header.ascx" %> 

<form runat="server">
<pagelet:header id="myPagelet" textboxvalue="pagelet control attribute" 
runat="server" />
<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.

This was last published in August 2003

Dig Deeper on Win Development Resources

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.