Now that we have the full setup lets test our controls using the default "webform1.aspx" page.
In order to use any usercontrol we must first add the register directive in the html part of our page.
<%@ Register TagPrefix="DNG" TagName="DateBox" Src="~/Controls/DateBox.ascx" %> |
And here is the trick, watch carefully the SRC. We are tricking the asp.net engine by using an App-Based path with the ~ prefix instead of a classic virtual path. If we had used a virtual path asp.net would have thrown the following error "maps to another application, which is not allowed". Using and App-Based path asp.net doesn't notice that the file comes from a different application and we can use our ascx files, great !
Lets move on and add our user controls to our page and compile the project.
<DNG:DateBox id="DateBox1" Company="DNG" Year="1984" runat="server" /> |
If we did everything correctly our shared user control should appear on our test page.
Looks nice ;)