I recently ran into a problem that had me stumped for a while. In one of my legacy ASP.NET 1.1 applications, I use a few different custom webcontrols where I’ve over-ridden the default render() method in order to produce different output. For example, I wanted to use a CheckBoxList web control, but I was unhappy with the way it rendered by default, for both the flow and table methods.
This worked fine for normal pages, and is usually not really a big deal. However, when it came time to using them in a project of mine that used Page.ParseConrols() to dynamically generate ASP.NET controls, I was always getting the error “Unknown server tag: blah”.
Page.ParseConrols() is not a very common method to use for generating ASP.NET pages, but in my case it was necessary. This particular application generated webpages by transforming XML using an XSL stylesheet, and then sought to render the results of that transformation to the page. However, I also wanted to be able to use the results of that transformation in codebehind, if the user wanted to perform a postback on the rendered page. So instead of using XSL to simply output common HTML tags, I output tags like asp:TextBox and asp:Button. Normally all this would do is print literal text of asp.net tags to the screen, because the webcontrols aren’t being processed. But Page.ParseConrols() allows you to pass a string to it, and it outputs a control that can be added to a PlaceHolder.
That description is a little muddled, but hopefully you sort of get the idea. Anyways, the problem came about when I tried to also use a custom webcontrol in this manner, alongside the regular asp.net webcontrols. It would always give me the unknown server tag error, even though I had clearly included my @Register TagPrefix directive on the page with the placeholder.
The trick was, you have to include the @Register directive along with the rest of the content that’s passed to Page.ParseConrols(). Once you include that directive as a prefix to the rest of the html, it works as expected.
See the following links for resources that helped me: