Register your User and Custom controls in the Web config
Usually when you wanted to register your control you would do it in the page and it would be something like this:
1 | <%@ Register tagPrefix="myControl" namespace="UserControls" assembly="UserControls" %> |
The problem
If you were working on a project with a few other developers, you would probably see that the tagPrefix would vary a bit. This might not be a big issue for some, but I prefer that things are called the same (for a couple of reasons). Therefore it would be nice if you would be able to make some sort of naming convention that could be controlled from one place. It would also be easier to maintain if you ever had to update all the declarations.
The solution
If you are working with .NET 2.0 you are in luck, if not, then you are screwed. The solution is to declare them (once) in the web.config.
1 2 3 4 5 6 7 8 9 | <configuration> <system.web> <pages> <controls> <add tagPrefix="myControl" namespace="UserControls" assembly="UserControls" /> </controls> </pages> </system.web> </configuration> |
When you have registered the control(s) then you can simple add the control to your page like this:
1 2 3 4 5 6 7 | <html>
<body>
<form id="form1" runat="server">
<myControl:MyControl ID="myControl1" runat="server" />
</form>
</body>
</html> |