R
richard.tallent
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.
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.