ASP.NET/C#: How to use a Subclassed Control on a Page?

Posted by Bob Kaufman on Stack Overflow See other posts from Stack Overflow or by Bob Kaufman
Published on 2010-03-12T13:07:35Z Indexed on 2010/03/12 13:57 UTC
Read the original article Hit count: 290

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET