all groups > asp.net building controls > march 2007 >
You're in the

asp.net building controls

group:

Removing Assembly Page Directive Attribute


Removing Assembly Page Directive Attribute larry
3/10/2007 11:33:13 AM
asp.net building controls:
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>

-----------------------------------------------------------------------------------------------------------------------------------------------------
Re: Removing Assembly Page Directive Attribute intrader
3/12/2007 6:16:31 PM
[quoted text, click to view]
The code for the control is kept in the project; no need to reference an
AddThis Social Bookmark Button