Removing Assembly Page Directive Attribute

Discussion in 'ASP .Net Building Controls' started by larry, Mar 10, 2007.

  1. larry

    larry Guest

    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>

    -----------------------------------------------------------------------------------------------------------------------------------------------------
     
    larry, Mar 10, 2007
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.