Contents
How do I register user control?
To include a user control in a Web Forms page
- In the containing ASP.NET Web page, create an @ Register directive that includes:
- In the body of the Web page, declare the user control element inside the form element.
- Optionally, if the user control exposes public properties, set the properties declaratively.
How can you register a custom server control to a Web page?
You can register a custom server control to a Web page using the @Register directive. Create an @ Register directive that includes: A TagPrefix attribute, which associates a prefix with the user control. This prefix will be included in opening tag of the user control element.
What is the last event of web page life cycle?
UnLoad – The UnLoad phase is the last phase of the page life cycle. It raises the UnLoad event for all controls recursively and lastly for the page itself. Final cleanup is done and all resources and references, such as database connections, are freed.
Why do I need to register controls in web.config?
If you need to use same user or custom controls on many pages, registering in every page looks a little bit hard coded and harder to maintain. By using web.config you have information on one place, which is easier to manipulate and change if needed.
How to register user controls and custom controls?
Note that the first two register directives above are for user-controls (implemented in .ascx files), while the last is for a custom control compiled into an assembly .dll file. Once registered developers could then declare these controls anywhere on the page using the tagprefix and tagnames configured.
How can I use user controls on my website?
Once you register the controls within the web.config file, you can then just use the controls on any page, master-page or user control on your site like so (no registration directives required):
How are custom server controls used in ASP.NET?
In previous versions of ASP.NET developers imported and used both custom server controls and user controls on a page by adding <%@ Register %> directives to the top of pages like so: