Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Web.config Is it possible to register all user controls in specified directory

Currently I'm registering every user control separately in Web.config

<pages validateRequest="false">
  <controls>
    <add tagPrefix="cc1" src="~/Controls/MyUserControl1.ascx" tagName="MyUserControl1"/>
    ...    
    <add tagPrefix="cc1" src="~/Controls/MyUserControlN.ascx" tagName="MyUserControlN"/>
  </controls>
</pages>

But from time to time I forget to checkin web.config. Actually, I usually forget that it have changed skip it because it often breaks settings others set to connect to their local db DB copy.

I was wondering is it possible to just specify whole Controls directory and get all controls there registered automatically

like image 399
Sergej Andrejev Avatar asked Mar 25 '09 07:03

Sergej Andrejev


People also ask

How do you register a user control *?

You add a user control to a page by registering it on the host page. When you register it, you specify the . ascx file that contains the user control, a tag prefix, and a tag name that you will use to declare the user control on the page.

How do you register user control in Azure?

Sign in to the Azure portal. From Azure Active Directory, select App registrations and click New registration. In the resulting pane, enter the name of the application (for example, MATLAB Production Server App ) then select Register.

Which property is used to set the user control on the form?

User Control properties are used to set the values of a User Control from the parent page.

Which directive is required to add a custom control to a Web form?

The Register Directive The Register derivative is used for registering the custom server controls and user controls.


1 Answers

Yes and no.

Basically, you can register all your usercontrols in the web.config. BUT you'll run into problems if you want to use any of your usercontrols within other usercontrols.

So, if you're never going to nest usercontrols, you're good to go. BUT if you want the flexibility to nest usercontrols you've got a few options:

  1. Register them all in the web.config, and then, in the case of nesting, register the control you're nesting directly in the parent usercontrol.
  2. As Bryan mentioned above, compile your usercontrols into an assembly, and reference them in the web.config.
  3. This is the worst option, but basically you can get around the nesting problem when registering all your usercontrols in the web.config by placing your controls in sub folders...not a great option.
  4. Another option is to strongly type your usercontrols, perhaps by creating base classes for your usercontrols.

Basically it's not a bug in the framework but a result of compiling everything into a single assembly. The app essentially can't distinguish between user controls.

There's some more info here and here. check out the comments on this one

like image 57
andy Avatar answered Sep 22 '22 22:09

andy