locked
Registering my own controls RRS feed

  • Question

  • User1431725092 posted

    Hi guys,

    As an experienced .NET developer I'm quite ashamed to be asking such a simple question, but it's been a while since I developed for web sites. I would hope that what I'm trying to do is extremely simple when you know how!

    In Visual Studio 2008, I have a solution containing a number of projects. All these projects have an output type of Class Library, except one, which has an output type of Web Application. My intention is to use the Web Application to test the server controls that I'm building in the Class Libraries.

    My Web Application has project references to the Class Libraries I want to test. All I want to do is register the controls in these libraries for use on my pages. It is essential that I'll be able to step into the server control's code in the Class Library while the page is executing, for debugging purposes. Ideally I'd rather reference them in the web.config than at the top of each page.

    I know that there are countless web pages on the internet that tell you how to register server controls, but I haven't found them helpful because all assume they're either in a strongly named external pre-compiled dll, or in the app_code folder of the web site. For me, neither of these is the case. I need to reference them via another project in the solution.

    Is anybody able to tell me what I should be doing, please?

    Very many thanks in advance of your help

    Ben

    Wednesday, June 18, 2008 9:56 AM

Answers

  • User543031324 posted

    Sorry, I was thinking of registering a type. This is how it should be

     

    <add tagPrefix="bench" namespace="Framework.UI.Web.WebControls" assembly="Framework.UI"/>
      

     

    The assembly attribute specifices "assemblyName, assemblyVersion, culture, publicKey". I was thinking of a type definition which goes "typeFullName, assemblyName, assemblyVersion, culture, publicKey". You should be able to just specifiy the assembly name in the add element because it will be referenced locally through a project resource (which copies it to the bin directory when you build the website). Sorry again for the confusion.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 19, 2008 10:57 AM

All replies

  • User543031324 posted

    Take a look at the servers web.config file (%WINDOWS%\Microsoft.NET\Framework\[Version]\CONFIG\web.config). This is where the "asp:" controls are defined.

      

    <pages>
        <controls>
            <add tagPrefix="my" namespace="My.Controls" assembly="My.Controls, My.Controls"/>
        </controls>
    </pages>
     

    Add something like that to the websites web.config file and everything should work great.

    Wednesday, June 18, 2008 10:26 AM
  • User1431725092 posted

    Thanks for your input. I've got the following to my web.config

    <pages masterPageFile="~/Site.Master">

    <controls>

    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add tagPrefix="bench" namespace="Framework.UI.Web.WebControls" assembly="Framework.UI, Framework.UI"/>

    </controls>

    </pages>

     

    Unfortunately, I get the following configuration error:

    Server Error in '/' Application.

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

    Parser Error Message: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

    Source Error:

    [No relevant source lines]


    Source File: none    Line: 0

     

     I've now managed to make it work, but only by specifying a strong name key file for each assembly, finding out the public key token, and putting a much longer string into the assembly attribute in the config file. It now reads:

     It now reads

    <add tagPrefix="bench" namespace="Framework.UI.Web.WebControls" assembly="Framework.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b1a202067946b4d4"/>

    I'm happy that it works, but I would like to get your way working if possible. Your way is neater and avoids me having to strong name all the assemblies and type the version, publickeytoken and culture into the web.config. Any ideas?

    Thursday, June 19, 2008 4:55 AM
  • User543031324 posted

    Where is you assembly located? if it is installed in the GAC, then you have to use the strong name or else the .NET framework will not know which version you want if there are multiple versions of the assembly. If you have set a project reference or placed your assembly in the bin directory of the web app, then you should be able to use my syntax.

    Thursday, June 19, 2008 8:05 AM
  • User1431725092 posted

    No, I'm not using the GAC. I've tried it, and made it work but it was a pain. I want to be able to do it your way ideally.

    My web site has a project reference to the assembly.

    On that project reference:

    Name = UI
    Aliases = Global
    Copy Local = True
    File Type = Assembly
    Identity = Framework.UI
    Resolved = True

    Based on that information, are you able to tell me what the value of the assembly attribute should be in the tag you showed in the web.config file, please?

    I've tried various combinations like:

    Framework.UI, UI
    UI, Framework.UI
    UI, UI
    Framework.UI, UI

    Perhaps you're able to clarify exactly why there are two comma separated values, and what each one represents?

    Thanks again

    Ben

    Thursday, June 19, 2008 10:34 AM
  • User543031324 posted

    Sorry, I was thinking of registering a type. This is how it should be

     

    <add tagPrefix="bench" namespace="Framework.UI.Web.WebControls" assembly="Framework.UI"/>
      

     

    The assembly attribute specifices "assemblyName, assemblyVersion, culture, publicKey". I was thinking of a type definition which goes "typeFullName, assemblyName, assemblyVersion, culture, publicKey". You should be able to just specifiy the assembly name in the add element because it will be referenced locally through a project resource (which copies it to the bin directory when you build the website). Sorry again for the confusion.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 19, 2008 10:57 AM
  • User1431725092 posted

    Thanks, that seems to have made it work!

    I appreciate your help.

    Friday, June 20, 2008 4:25 AM