Tip

Pagelet 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.

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.


Source: DotNetExtreme.com

This was first published in August 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.