I dynamically create a User Control from XML via XSLT. Output is a string with a content like this:
<%@ Control Language="C#" AutoEventWireup="true" Inherits="Library.Web.UI.GeneratedFormBase, MyAssembly" %>
<div class="myCssClass">
<asp:TextBox ID="d" runat="server" OnTextChanged="OnTextChanged" />
<asp:Label runat="server" AssociatedControlID="SomeName" AccessKey="n">Label Text</asp:Label>
<asp:TextBox ID="SomeName" runat="server" OnTextChanged="OnTextChanged" />
<asp:Label runat="server" AssociatedControlID="SomeOtherName">Welcome</asp:Label>
<asp:TextBox ID="SomeOtherName" runat="server" OnTextChanged="OnTextChanged" />
<asp:Button ID="OK" runat="server" OnClick="ButtonClick" Text="Save" />
</div>
I now use Page.ParseControl(theGeneratedString) to create this control dynamically.
The type that is declared in Inherits
is existing and can be found. If I declare another (i.e. non-existing) type there, a Parser Error
Exception is thrown, so I am totally convinced that the parser looks for this type and finds it.
Nevertheless, the Control that is generated from the ParseControl
is of type System.Web.UI.Control and not of the control that is stated (and obviously also parsed and located) in the Inherits-declaration.
Why is that and how can I ensure that the control is of the correct type?