User controls are containers into which you can put markup and Web server controls. You can then treat the user control as a unit and define properties and methods for it. User controls are substantially easier to create than custom controls, because you can reuse existing controls. They make it particularly easy to create controls with complex user interface elements.
Heilights of user control;
- .ascx files
- Use of @Control directive instead of @Page
- Cannot be run as a stand alone application, requires an aspx page
- No html tags like html, body, form. Other tags are allowed
Steps to create user control;
- Create a web application from Visual studio
- Select project from solution explorer -> right click, Add new item -> Web User control
- Add controls and related events
- Add an aspx page to the project
- Make use of @Register directive to use created user control
Example:
Page Design -
Page header -
Server script -