Search code examples
asp.netcustom-server-controls

How do I get ASP.NET to recognize my custom server control?


I am trying to create my first ASP.net server control derived from a Panel. For some reason, I am unable to get the .aspx page to recognize my server tag even though the application recognizes the class and namespace of my control.

Here are the steps I've used:

1) I created a class CollapsablePanel that I've placed in my site_code directory. I am using a Web App not Web Site so App_Code is not really available to me.

Namespace webstation.WebControls

    Public Class CollapsablePanel
        Inherits System.Web.UI.WebControls.Panel


    End Class

End Namespace

2) In the .aspx file I've added <%@ Register TagPrefix="webstation" Namespace="MyApplication.webstation.WebControls" %>

I've built the project but my custom tag prefix does not appear. If I just go ahead and type the editor does not throw an error, however the page does when I publish it and try to access it. If I try to access the class from the codebehind (Imports MyApplication.webstation.WebControls) the custom control appears in intellisense, so I know that Visual Studio is reading the class information to some extent.

What am I doing wrong here? Any thoughts are greatly appreciated.

Mike


Solution

  • I was able to get it work like expected once I went ahead and created a Class Library project in the same solution, built the project, copied the DLL from the bin of the Class Library and placed it in a folder of my Web Project used for holding external binaries. I also added a reference to the .dll in the project. Once I did that, then the syntax:

    <%@ Register Assembly="webstation.WebControls" Namespace="webstation.WebControls" TagPrefix="webstation" %>
    

    began to work. Does anyone know if I am able to somehow automatically update the compiled .DLL in my web project from the class library in the same solution? Or do I just have to go into the bin folder each time and manually copy it into the web project?

    Thanks,

    Mike