if the custom control is in App_Code folder, than what will be it's assembly name in the <%@register

Discussion in 'ASP .Net' started by Umut Tezduyar, Dec 21, 2005.

  1. I know that, in asp.net 2.0, the assembly for the web site is splitted into
    pieces and each time you build it, it generates a random name for assembly.

    My question is, if i create a custom web control under the App_Code folder,
    how can i add a register tag on a page.

    <%@ Register TagPrefix="ABC" Namespace="ABC.Foo" Assembly="???????????????"

    My other question is "Since i don't know the name of the assembly of the
    asp.net 2.0 web site, how can dynamically load that assembly using the
    Assembly.CreateFromFile () method??

    Thank you
    Umut Tezduyar, Dec 21, 2005
    1. Advertisements

  2. Umut Tezduyar

    Brock Allen Guest

    Use "__code":

    <%@ Register TagPrefix="ABC" Namespace="ABC.Foo" Assembly="__code" %>
    Brock Allen, Dec 21, 2005
    1. Advertisements

  3. Thank you so much.

    How can i load that assembly on the fly using
    Assembly.LoadFrom ()
    Umut Tezduyar, Dec 22, 2005
  4. Umut Tezduyar

    Brock Allen Guest

    Why would you need to manually load the assembly? Just call "new" on the
    control/class defined in the App_Code directory.
    Brock Allen, Dec 22, 2005
  5. I have a custom control on a seperate assembly. I give a reference to that
    custom control from web site. This web control loads "custom controls" that
    are under the app_code folder. Maybe i am not clear but, i definetely need
    to find a way to load them.

    This is the inside of the load method. This was valid at 1.1. It is no more
    valid at asp.net 2.0

    // The assembly will be searched in the bin folder of the application

    string path = AppDomain.CurrentDomain.BaseDirectory + "bin" + "/" +
    cstModule.Assembly + ".dll";

    // Load assembly

    ass = Assembly.LoadFrom(path);

    // Load control from assembly

    control = (System.Web.UI.Control)ass.CreateInstance(cstModule.TypeName);
    Umut Tezduyar, Dec 22, 2005
  6. By the way, it gives an error for _code

    <%@ Register Assembly="_code" Namespace="A" TagPrefix="abc" %>

    Error 3 Could not load file or assembly '_code' or one of its dependencies.
    The system cannot find the file specified. C:\Documents and
    Settings\utezduyar\My Documents\Visual Studio
    2005\WebSites\WebFrameworkTestSite\Default.aspx 2
    Umut Tezduyar, Dec 22, 2005
  7. <%@ Register Assembly="App_Code" Namespace="A" TagPrefix="abc" %>

    This is working perfectly.
    Umut Tezduyar, Dec 22, 2005
  8. I found the solution for this.

    System.Reflection.Assembly.Load (string assemblyName) solves all of my

    System.Reflection.Assembly.Load ("App_Code") works perfectly.
    Umut Tezduyar, Dec 22, 2005
  9. Umut Tezduyar

    Brock Allen Guest

    Two underscores in __code.
    Brock Allen, Dec 22, 2005
    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.