ASP.NET/C#: How to use a Subclassed Control on a Page?
- by Bob Kaufman
I've subclassed DropDownList to add functionality specific to my application:
public class MyDropDownList : DropDownList
{
...
}
... then referenced it in Web.Config, which is where I figure things start to go wrong:
<pages theme="Main">
<controls>
<add tagPrefix="bob" tagName="MyDropDownList" src="~/Components/MyDropDownList.cs" />
</controls>
</pages>
my reference to it does not work:
<tr><td>Category</td>
<td><bob:MyDropDownList runat="server" ID="Category"... />
and my best clue is the complier error message:
"The file 'src' is not a valid [sic] here because it doesn't expose a type."
I figure I'm misapplying knowledge of how to create a Web User Control here. What I want to be able to do is refer to this control on an ASP.NET page just like I would the parent DropDownList. Refactoring back into a Web User Control that contains a DropDownList is not desirable, because I want to apply a RequiredFieldValidator to it.