5

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.

Owidat
  • 1,071
  • 2
  • 15
  • 20

2 Answers2

7

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.

Rafał Warzycha
  • 561
  • 3
  • 18
  • Thank's @rwarzycha , OK how to prevent this from happening? I don't want it load even if it's registered. – Owidat Feb 04 '12 at 10:48
  • Could you provide some more info, why are you do not want this workflow? It is by design. What is your case? – Rafał Warzycha Feb 07 '12 at 07:47
  • My case is that we are developing a CMS, and one of the CMS features is that admin users (Developers/Designers) can create dynamic pages by creating master pages and adding controls to a page but sometimes they add the control for testing then remove it and they forget to remove Register Directive .. But now after reading Scottgu post I know the solution to my case. Thank's @rwarzycha – Owidat Feb 09 '12 at 07:21
1

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.

Nandun
  • 1,802
  • 2
  • 20
  • 35