Registering .ascx ASP.NET User control in ASP.NET Page or Master Page will load it or not?

13,176

Solution 1

In this case your user control will be loaded to the page object in server side, that mean it will be processed with whole lifecycle of ASP.NET app, but because you don't create control instance non output html will be rendered. You are using 'type' but not the 'instance'.

Answering you question: yes, it will be loaded, but not rendered, databounded, etc...

Edited 2/7/2012

If you want to get rid of the Register Directive, you always could use web.config - follow instructions of this Scottgu post.

Solution 2

Register directive is only there to create an association between the prefix and the control. It only matters when loading controls declaratively. Its only there to make development easy.

there is no way that Page_Load or any private methods can be called unless you have declared an instance of your control somewhere.

besides, if you have not used anywhere in the code, you shouldn't have the Register directive. IMO i don't think the Register directive is causing this problem.

Share:
13,176
Owidat
Author by

Owidat

Application Developer, Database Administrator. Particularly interested in client/server and relational database design using MYSQL, and MS-SQL Server. Always interested in ASP.NET web application projects, as well as layout desing and JQuery. Specialties I can do the following: - Web application development and design. - Database management. - Website layout design (Web 2.0, HTML5, CSS, CSS3). - JavaScript Libraries.(JQuery, Mootools). - Open source web applications. (ASP.NET: DotNetNuke, Sitefinity, mojoportal, nopcommerce, ... ) (PHP: Joomla, Wordpress, phpbb, Drupal, ...) - Server Administration - SharePoint Administration - SharePoint Development - SharePoint Apps - Mobile Apps - Windows Phone - Windows Store - Icenium - KendoUI (Moible) - Web Services (OData, Web API, SOAP, WCF)

Updated on June 20, 2022

Comments

  • Owidat
    Owidat almost 2 years

    If I register user control in ASP.NET page, the control will be loaded to the page or not?
    <%@ Register Src=".." TagName="tag" TagPrefix="pre" %>
    even if I not call it in the page using?
    <pre:tag id='control123' />

    because part of my code is executed even if I'm not calling the control, I found that when I did performance profilling.