Use custom server control syntax to declare user controls and custom server controls within the body of an ASP.NET Web page. For this syntax to work, the control must be registered on the page or in a configuration file (you can register a control on all pages of an application by adding it to the <controls> of the Web.config file). You can register a control on an individual page by using the @ Register directive.
The opening tag of an element for a user or custom control must include a runat="server" attribute/value pair. To enable programmatic referencing of the control, you can optionally specify a unique value for the id attribute.
Any properties that you have authored on a user or custom server control can be exposed declaratively in the opening tag of the server control. Simply declare the property as an attribute and assign it a value. For example, if you create a custom text box control with a width property, declaring width="50" in the opening tag of the control sets the server control's display width to fifty pixels.
In some cases, attributes might be objects that have their own properties. In this case, include the property name in the declaration. For example, if you create a custom text box control that includes a font attribute, it can include a name property. You can then declare the property in the opening tag of the server control as font-name="Arial". For more information about developing custom server controls with properties, see Server Control Simple Properties and Subproperties.
You can declare events with custom server controls and user controls in the same way you would with any ASP.NET server control. Specify the event binding in the opening tag of the server control with an attribute and value. For more information on authoring custom server controls that support events, see Server Event Handling in ASP.NET Web Pages.
You can use and develop custom server controls that support inline templates. For details on how to declare templates in a custom server control, see Server Control Inline Template Syntax. To learn how to author custom server controls that support inline templates, see How to: Create Templated ASP.NET User Controls.