Brief of User Control

A user Control contain existing ASP.NET controls into a single container control, which you can easily reuse throughout your web project.

User controls represent the most basic form of ASP.NET visual encapsulation. Because they are the most basic, they are also easy to create and use. Essentially, a user control is used to group existing server controls into a single-container control. This allows you to create powerful objects that you can use easily throughout an entire web project.

User controls allows you to group logically related content and controls together so that they can be treated as a single unit in content pages, master pages, and inside other user controls. A user control is actually a sort of mini-ASPX page in that it has a markup section and, optionally, a Code Behind file in which you can write code for the control. Working with a user control is very similar to working with normal ASPX pages, with a few minor differences.

User controls have the following similarities with normal ASPX pages:
They have a markup section where you can add standard markup, server controls, and plain HTML.

They can be created and designed with Visual Studio in Markup, Design, and Split View.

They can contain programming logic, either inline or with a Code Behind file.

They give you access to page-based information like Request.QueryString.

They raise some (but not all) of the events that the Page class raises, including Init, Load,and PreRender.
User controls have an .ascx extension instead of the regular .aspx extension. In addition, user controls cannot be requested in the browser directly. Therefore, you cannot link to them. The only way to use a user control in your site is by adding it to a content or master page or another user control.

User Controls are composed of a markup portion with HTML and Control Tags (the .ascx file) and can optionally use a code-behind file with event – handling logic.

The Difference between users controls and web pages are:
User Controls use the File extension .ascx but web pages use the File extension .aspx.

The .ascx file for a user control begins with a <%@Control%> directive but the .aspx file for a web pages begin with <%@Page%> directive.

User Controls cannot be requested directly by a web browser but they are embedded inside other web pages.
User Control is embedded inside a web form.
To embedded the user control inside a web Form, you need to
To Add a Register Directive to the page.

To Add the User Control anywhere in the Body.

Scroll to Top