Two Issues with Custom Control with ASP.NET Site
-
Good Afternoon, I am working on a project where I will need a custom control added to a site. Since I have never worked with them previously, I decided to try and make a very basic control and a test site so I can learn how to do everything properly. For instructions, I was using the steps outlined on Microsoft's website here. Therefore I created a solution with two projects - Custom Control Assembly and Custom Control Test Site, both of which are using the 4.7 version of the .NET Framework. For the Custom Control Assembly, the Assembly name is CustomControlAssembly and the Default namespace is CustomControlNamepsace. There is one file in the project called CustomControl which inherits from
System.Web.UI.Control
. This project built without any errors and I copied the CustomControlAssembly.dll to the /Custom Control Test/Custom Control Test Site/bin folder as instructed on the Microsoft page listed above. The Custom Control Test Site is a web forms site. On the Default.aspx page I added the following directive right underneath the
<%@ Page %>
directive:
<%@ Register TagPrefix="Custom" Namespace="CustomControlNamespace" Assembly="CustomControlAssembly" %>
In the page, I am able to add the following tag and IntelliSense correctly finds it:
However, if I try to add an ID properties (in order to name it like I do with all ASP.NET controls), like the following:
I get the following error message: CS0400 - The type or namespace name 'CustomControlNamespace' could not be found in the global namespace (are you missing an assembly reference?) If I take the ID="CustomControl1" out of the tag, then the site will build fine again. However, when I run the site, the custom control does not show anything on the site. I tried updating the CustomControl to inherit from
System.Web.UI.UserControl
instead of
System.Web.UI.Control
but it still doesn't display on the Default.aspx page. The following is the markup of the CustomControl.ascx file: