Export (0) Print
Expand All

Introduction to Web User Controls

The ASP.NET server controls provide a great deal of functionality, but they cannot cover every situation. Web user controls enable you to easily define controls as you need them for your applications, using the same programming techniques that you use to write Web Forms pages. You can even convert a Web Forms page into a Web user control with a few modifications. (For details see Walkthrough: Converting a Web Forms Page to a User Control.) To make sure that a user control cannot be run as a standalone Web Forms page, user controls are identified by the file name extension .ascx.

Note   Web user controls are not to be confused with Web custom controls. For more information, see Recommendations for Web User Controls vs. Web Custom Controls.

User Control Structure

A Web user control is similar to a complete Web Forms page, with both a user interface page and a code-behind file. The user interface page differs from an .aspx file in these ways:

  • The extension must be .ascx.
  • The user control does not have <HTML>, <BODY>, and <FORM> elements in it (these elements must be in the hosting page).

In every other way, a user control is like a Web Forms page. You can use the same HTML elements and Web controls on a user control that you do on a standard Web Forms page. For example, if you are creating a user control to use as a toolbar, you can put a series of Button Web server controls onto the control and create event handlers for the buttons.

See Also

Creating Web User Controls | Adding User Controls to a Web Forms Page | Introduction to Web Custom Controls | Recommendations for Web User Controls vs. Web Custom Controls | Walkthrough: Creating a Web User Control

Show:
© 2014 Microsoft