Efficiency of dynamically adding web user controls

  • Thread starter Thread starter MC D
  • Start date Start date
M

MC D

When I dynamically add a control by doing something like

dim x as control = Page.LoadControl("myControl.ascx")

am I actually loading the control from disk??? I don't really understand why
I can't access the class for the user control directly... in other words
just say:

dim x as new myControl()

(which doesn't generate an error, but it wil not render the UI)

If I'm adding a control dozens of times on a page, is this very
in-efficient?

Thanks for any help!

-D
 
User controls bear some resemblence to include files. Of course they are
object oriented, much more flexible, etc.

There are many large systems that rely on include files, and those work ok -
so I would imagine user controls wouldn't be any worse.
 
Do not forget that some user controls are not just classes, but also contain
html snippets in the actual ascx file. It is for the purpose of retreiving
both the class, and the html within the ascx file, that page.loadcontrol()
is used.

User Controls are most helpful when creating commonly used UI components.
If your user control has no associated html in the .ascx file, I'd recommend
creating a simple class or a server control instead.



I was minding my own business when MC D blurted out:
 
Back
Top