.NET Samples - ASP.NET Web Forms User Controls

This section includes the following samples:

Pagelet7 Sample

Pagelet6 Sample

Pagelet5 Sample

Pagelet4 Sample

Pagelet1 Sample

Pagelet2 Sample

Pagelet3 Sample

Pagelet7 Sample

This sample demonstrates the page's LoadControl method, which is used to dynamically load a user control, passing the virtual path to the user control's source file.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

Control; Page; DataBinder; Container; Binder; DataList; HtmlGenericControl; DataAdapter; Import; String; SqlDataAdapter; DataSet; SqlConnection; EventArgs; Publisher; Publish; Table; Object

Pagelet6 Sample

This sample demonstrates a product-listing user control that internally handles its own postback events. A user control can handle its own events, encapsulating some of the page logic from the containing Web Forms page.

Namespaces used in this sample:

System.Data; System; System.Data.SqlClient

Classes used in this sample:

DataList; ListItem; DataBinder; Binder; Container; SqlDataAdapter; DataSet; SqlConnection; DataAdapter; Page; DropDownList; Object; EventArgs; Import; Table; Publish; Publisher; Control

Pagelet5 Sample

This sample demonstrates another useful user control for collecting user names and passwords, this time with input validation.

Namespaces used in this sample:

(none)

Classes used in this sample:

Control; Label; Page; RequiredFieldValidator; Font; RegularExpressionValidator; String; TextBox; Button; EventArgs; Object

Pagelet4 Sample

This sample demonstrates another useful user control for collecting user names and passwords.

Namespaces used in this sample:

(none)

Classes used in this sample:

Label; String; Page; TextBox; Object; Control; EventArgs; Button

Pagelet1 Sample

This sample shows a user control imported into another Web Forms page. Developers can easily define their own controls using the same programming techniques for writing Web Forms pages. In this sample, the user control is a simple static file.

Namespaces used in this sample:

(none)

Classes used in this sample:

Message; Page; Control

Pagelet2 Sample

This sample shows an extension of the previous Pagelet1 sample that adds two public String fields. These fields can be set either declaratively or programmatically in the containing page.

Namespaces used in this sample:

(none)

Classes used in this sample:

Message; String; Control; Object; EventArgs

Pagelet3 Sample

This sample demonstrates an Address user control that wraps the text properties of TextBox controls within it. The benefit of doing this is that the control inherits the automatic state management of the TextBox control for free.

Namespaces used in this sample:

(none)

Classes used in this sample:

String; Label; Form; Control; Object; EventArgs