views:

267

answers:

2

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.

+3  A: 
<pages theme="Main">
    <controls>
        <add tagPrefix="bob" namespace="MyProject" assembly="MyProject" />
    </controls>
</pages>

That should do the trick.

Joop
Based on what I've been reading so far, this sounds better than what I'm doing. It doesn't work, tho', and I think it's because the containing project is a "Web Site" rather than a "Web Application". I'm going to create a sub-project, drop it in there, make the appropriate reference in Web.Config then report back.
Bob Kaufman
Works! Thank you!
Bob Kaufman
A: 

@Joops answer saved me.

What I did differently was to register the namespace at the top of my page because I didn't need it everywhere.

ie.

<%@ Register TagPrefix="myTagPrefix" Namespace="MySolution.MyProject.Foo.Bar"
        Assembly="MySolution.MyProject" %>

cheers Joop!

Pure.Krome