Removing Assembly Page Directive Attribute

L

larry

Hi,

I was trying to create a very basic custom control that simply outputs
a literal string and the and date. After creating the custom control
class, I referenced the custom control in a webpage. When I added the
following an attribute "Assembly" in the page directive which I
assumed would take compile the custom control and make its
functionality available to to the webpage. When I ran the
application, I got an error

"Could not load file or assembly 'CustomControlTest' or one of its
dependencies. The system cannot find the file specified"

Source error:

<%@ Register TagPrefix="CC" Namespace="MyCustomControls"
Assembly="CustomControlTest" %>

When I removed the Assembly attribute from the page directive, the
application worked fine. How does the webpage know where the class to
be compiled is and why does adding the "Assembly" attribute give me an
error. The following is the source code, but I'd be most appreciative
if someone could elaborate on when or when not to use the "Assembly"
attribute when creating controls.

Source code
----------------------------------------------------------------------------------------------------------------------------------------------------------------

Imports Microsoft.VisualBasic
Imports System
Imports System.Web
Imports System.Web.UI

Namespace MyCustomControls
Public Class CustomControl1 : Inherits Control
Protected Overrides Sub Render(ByVal Output As
System.Web.UI.HtmlTextWriter)
Output.Write("This my my custom control! The time is now "
& DateTime.Now.ToString)

End Sub

End Class
End Namespace

The code for the webpage is as follows:
-------------------------------------------------------------------------------------------------------------------------------------------------------

<%@ Register TagPrefix="CC" Namespace="MyCustomControls"
Assembly="CustomControlTest" %>


<html>
<body>
<form method="POST" action="Default.aspx" runat="server">
The custom control produces the following output
<CC:CustomControl1 runat="server" />
</form>
</body>
</html>

-----------------------------------------------------------------------------------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top