Automatic <%@Register of Web User Controls in a Project?

A

Alex Maghen

Hi. In the shiny new ASP.NET 2.0, if you have a web project and you create a
set of User WebControls, is there a way to set those controls so that I don't
have to insert the whole
<%@ Register tagprefix="XYZ" Tagname="MyControl"
Src="~/BlahBlah/MyControl.ascx" %>

at the top of every page in order to use the control on that page? I *think*
I remember that there's a way of installing the control "globally" for the
whole server machine. I really don't want to do that. I just want to make it
accessible to the project without the whole ugly <%@Register tag.
 
T

Teemu Keiski

Hi,

yes. It's been added that you can specify global control registration in
web.config (for your web app). For example:

<pages>
<controls>

<!-- Uses the specified source for the user control -->
<add
tagprefix="MyTags3"
tagname="MyCtrl"
source="MyControl.ascx"/>
</controls>
</pages>
 
A

Alex Maghen

That rocks! Thanks.

Teemu Keiski said:
Hi,

yes. It's been added that you can specify global control registration in
web.config (for your web app). For example:

<pages>
<controls>

<!-- Uses the specified source for the user control -->
<add
tagprefix="MyTags3"
tagname="MyCtrl"
source="MyControl.ascx"/>
</controls>
</pages>

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
 
G

gerry

Am I missing something here ?

I have a number of custom WebControls, the @ Register is added to the page
and the dll copied to the bin folder automagically just by dragging the
control onto a webform - zero manual intervention required.

???

Gerry
 
T

Teemu Keiski

Certainly,

mostly a matter of preference. On the other hand, it's nice to be able to
reegister via web.config since registration is automatically applied for new
pages as well.
 
G

gerry

I'm not sure I understand your statement, dragging a control onto a page
does all the necessary registration - how much more automatic can you get ?
 
T

Teemu Keiski

Yes, you are correct,

but maybe if same control is used all over the site, registration is just
cleaner to keep in one, centralized place instead on every page. Especially
if you have lots of controls used extensively on multiple pages (or all)?
Keeps the directives shorter.
 
S

Steven Cheng[MSFT]

Thanks for Teemu's informative suggestion.

Hi Alex,

In addition to registering ascx usercontrol, the
<system.web><pages><controls>.... </..>.... element can also be used to
register custom webserver control for application scope. So if you've
developed some custom webserver controls that'll be used in most pages in
the application, you can also consider using this configuration setting.

BTW, the <pages> setting is also configurable in sub virtual or physical
directory, therefore we can also make a certain sub virtual directory in
our application register a particular group of controls.

#controls Element for pages (ASP.NET Settings Schema)
http://msdn2.microsoft.com/en-us/library/ms164640.aspx

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top