ASP.Net User Controls


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;

  1. Create a web application from Visual studio
  2. Select project from solution explorer -> right click, Add new item -> Web User control
  3. Add controls and related events
  4. Add an aspx page to the project
  5. Make use of @Register directive to use created user control
Example:

Page Design -

Page header -

Server script -



No comments:

Post a Comment