User Controls are customized controls that can be created based on the needs of users. ASP.NET provides this feature to assist developers to create controls with special or customized functionalities that standard Web Server Control does not have. User Controls are usually used in combination of a set of Web Server controls and functionality for reuse in multiple places of a site. User Controls look like any Web Forms with UI files to design the controls layout as well as the code behind file to write the code. Although they look similar, there are some noticeable difference when compared with a common Web Form.
i. The file extension of a User Control is .ascx.
ii. Contains @ Control directive in the UI File that defines the
control’s configuration.
iii. Only works when hosted in a Web Form. It is not executable as
an independent file.
iv. , and
elements
are not used in UI file. User controls are hosted in a Web Form by registering it in the host file. Below is an example how the User Control is registered.
<%@ Register
src="UserControls/UC1.ascx"
tagname="UC1"
tagprefix="uc1"
%>
“Src” refers to the User Control file. “Tagname” is used to identify a User Control file. "Tagprefix” is used to specify unique namespace for the User Control. In Visual Studio, the @ Register directive will be automatically populated in the host file when the User Control is embedded in the host file.
A User Control may have custom build properties which can be consumed by the host file. These properties are created in the same way as how properties are created in a Web Form.
A User Control may also have Web Server Controls such as Buttons that would require an Event Handler such as Button_Click to be created to respond to user’s action. However, events raised by Web Server Controls in User Controls would not be available in User Control files. To resolve this problem, an event needs to be defined and raised in the User Control file and notified to the host file.

