Connecting Tech Pros Worldwide Forums | Help | Site Map

Avoiding @Register, cannot instantiate controls registered in web.config (2.0)

richard.tallent@gmail.com
Guest
 
Posts: n/a
#1: Jan 27 '06
I'm fond of web controls in ASP.NET, but the need for <@ Register%>
blocks at the top of each page is a pain.

ASP.NET 2.0 has a way to centrally register controls in the web.config
file, but it is poorly documented and appears to be broken.

I have added my standard user controls to my web.config file. The MSDN
examples are flat wrong, by the way (bad XML case and attribute names,
won't compile). The proper syntax for registering server and user
controls is as follows:

<configuration><system.web><pages><controls>
<add tagPrefix="RST" namespace="RST.UI" assembly="RST.UI" />
<add tagPrefix="RST" tagName="Header"
src="~/controls/header.ascx" />
</controls></pages></system.web></configuration>

Ok, so now I can use declarative instantiation on any ASPX page,
without the need for a page-level @Register directive:

<RST:Header runat="server" id="MyHeader" />

And, with at least one instance of a particular control created that
way, I can programmatically create others:

Public Sub Page_Load()
' ClassName="Header" in the header.ascx
Dim o As New ASP.Header
End Sub

The problem is, I am usually creating *every* instance of some controls
dynamically in the Page_Load() method. But without at least one
declarative instance or an @Register directive, I get the following
error:

Type 'ASP.MyHeader' is not defined.

What am I missing here? Creating dummy instances of every control class
is even worse than having an army of @Register directives on every page.


Nathan Sokalski
Guest
 
Posts: n/a
#2: Jan 28 '06

re: Avoiding @Register, cannot instantiate controls registered in web.config (2.0)


I will admit that I have not tried using web.config in place of the
@register directive, but in your example you have an attribute of

assembly="RST.UI"

I could be wrong, but aren't assemblies usually .dll files? I think that
there might be a way to add a line in the AssemblyInfo.vb (or whatever file)
file that does what you want. Try looking into that, although I won't make
any promises since I prefer the simple @register technique, I don't think
it's that bad when all you have to do is a little copy & pasting. Good Luck!
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

<richard.tallent@gmail.com> wrote in message
news:1138401144.585006.15990@g49g2000cwa.googlegro ups.com...[color=blue]
> I'm fond of web controls in ASP.NET, but the need for <@ Register%>
> blocks at the top of each page is a pain.
>
> ASP.NET 2.0 has a way to centrally register controls in the web.config
> file, but it is poorly documented and appears to be broken.
>
> I have added my standard user controls to my web.config file. The MSDN
> examples are flat wrong, by the way (bad XML case and attribute names,
> won't compile). The proper syntax for registering server and user
> controls is as follows:
>
> <configuration><system.web><pages><controls>
> <add tagPrefix="RST" namespace="RST.UI" assembly="RST.UI" />
> <add tagPrefix="RST" tagName="Header"
> src="~/controls/header.ascx" />
> </controls></pages></system.web></configuration>
>
> Ok, so now I can use declarative instantiation on any ASPX page,
> without the need for a page-level @Register directive:
>
> <RST:Header runat="server" id="MyHeader" />
>
> And, with at least one instance of a particular control created that
> way, I can programmatically create others:
>
> Public Sub Page_Load()
> ' ClassName="Header" in the header.ascx
> Dim o As New ASP.Header
> End Sub
>
> The problem is, I am usually creating *every* instance of some controls
> dynamically in the Page_Load() method. But without at least one
> declarative instance or an @Register directive, I get the following
> error:
>
> Type 'ASP.MyHeader' is not defined.
>
> What am I missing here? Creating dummy instances of every control class
> is even worse than having an army of @Register directives on every page.
>[/color]


richard.tallent@gmail.com
Guest
 
Posts: n/a
#3: Jan 30 '06

re: Avoiding @Register, cannot instantiate controls registered in web.config (2.0)


The assembly name is "RST.UI.dll", and the register directive leaves
off the DLL. But this issue applies both to DLL and ASCX controls.

Copy and paste is never a good programming practice. I make heavy use
of custom controls, so centralization is a key requirement, and I don't
want to give up using ASCX files in the process.

Nathan Sokalski
Guest
 
Posts: n/a
#4: Jan 30 '06

re: Avoiding @Register, cannot instantiate controls registered in web.config (2.0)


Did you try looking into a way of adding something to the AssemblyInfo.dll
file that accomplishes what you want? I'm not sure exactly what it would be,
but I seem to remember reading something about a way to use AssemblyInfo.dll
that might accomplish what you want.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

<richard.tallent@gmail.com> wrote in message
news:1138634349.531122.313590@g49g2000cwa.googlegr oups.com...[color=blue]
> The assembly name is "RST.UI.dll", and the register directive leaves
> off the DLL. But this issue applies both to DLL and ASCX controls.
>
> Copy and paste is never a good programming practice. I make heavy use
> of custom controls, so centralization is a key requirement, and I don't
> want to give up using ASCX files in the process.
>[/color]


richard.tallent@gmail.com
Guest
 
Posts: n/a
#5: Jan 31 '06

re: Avoiding @Register, cannot instantiate controls registered in web.config (2.0)


Nathan, thanks, but I think you are missing the point. ASCX files don't
*have* an AssemblyInfo.dll file, they are standalone, plain-text files
that are compiled dynamically by ASP.NET.

ASP.NET is supposed to offer this functionality now via the web.config
file, but it appears to not work as advertised, and the SDK
documentation is completely useless.

Nathan Sokalski
Guest
 
Posts: n/a
#6: Feb 1 '06

re: Avoiding @Register, cannot instantiate controls registered in web.config (2.0)


I apologize, I meant to say the AssemblyInfo.vb file. This is a file
required by all ASP.NET applications written in VB.NET (if you are using C#
it is called AssemblyInfo.cs). Like I have mentioned before, I have never
modified this file, so I don't know everything that can be put in it or what
it can be used for, I am simply suggesting that you look into it.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

<richard.tallent@gmail.com> wrote in message
news:1138695338.729910.201040@g44g2000cwa.googlegr oups.com...[color=blue]
> Nathan, thanks, but I think you are missing the point. ASCX files don't
> *have* an AssemblyInfo.dll file, they are standalone, plain-text files
> that are compiled dynamically by ASP.NET.
>
> ASP.NET is supposed to offer this functionality now via the web.config
> file, but it appears to not work as advertised, and the SDK
> documentation is completely useless.
>[/color]


Closed Thread