trying to register my controls in web.config

Last post 06-27-2007 11:34 AM by Flip. 5 replies.

Sort Posts:

  • trying to register my controls in web.config

    06-12-2007, 10:23 AM
    • Loading...
    • Flip
    • Joined on 05-24-2007, 9:57 AM
    • Posts 3

    I just got back from Tech Ed and something I want to try out is registering a tagPrefix in web.config.  When I do that, I start getting all kinds of compile errors and 80% of them point to the attributes in web.config, then the rest are complaining about not being able to find the controls on the page.  I've google'd/searched for answers, but I can't seem to find anything.

    The challenge I think I'm having is the controls I'm using are in my project, but not in the App_Code directory, therefore I'm not sure what the assembly is.  I was trying to use the Namespace or the Src attributes for the <Add element.

     Can anyone help please?  Has anyone seen this before?  Do you have any page references?  Thanks.

  • Re: trying to register my controls in web.config

    06-12-2007, 11:06 AM
    • Loading...
    • jackyang
    • Joined on 11-16-2006, 7:27 PM
    • Canada
    • Posts 420

    In your website project, reference the class project inside \bin folder. 

    In your web.config:

    <system.web>
        ...
        <pages>
          <controls>
            ...
            <add assembly="MyNamespace" namespace="MyNamespace.UI.WebControls" tagPrefix="myControl" />
            ...
          </controls>
        </pages>
       ...
    <system.web>

     

     Then in all your aspx pages, you can simply use <myControl:SomeControl runat="server" ID= .../>

    Jack Yang
    .NET Developer
  • Re: trying to register my controls in web.config

    06-12-2007, 11:06 AM
    • Loading...
    • mosessaur
    • Joined on 07-11-2002, 6:40 PM
    • Cairo
    • Posts 352

    Have a look at this post at ScottGu's Blog
    Tip/Trick: How to Register User Controls and Custom Controls in Web.config
    .

    Make sure that your code is compiling correctly, and your themes folder dosen't contain any unused files or has incorrect controls syntax.

    If you wish to register controls assembly try this:

    <pages>
      <
    controls>
        <add assembly="SCS.WebControls" namespace="SCS.WebControls" tagPrefix="scs"/>
        
    <add assembly="ThirdParty.Controls" namespace="ThirdParty.Controls" tagPrefix="thirdparty"/>
        <!--the following is registration for controls in App_Code where no assembly is defined make sure to give your controls namespace -->
        <add namespace="MyControls" tagPrefix="ctrl"/>  
    </controls>
    </
    pages>

    Muhammad M. Mosa Soliman
    Software Engineer
    Moses's Blog
  • Re: trying to register my controls in web.config

    06-12-2007, 11:49 AM
    • Loading...
    • Flip
    • Joined on 05-24-2007, 9:57 AM
    • Posts 3

    re assembly

    That is part of my problem, I don't have/know what the assemblies are, or if I have any?  The controls I'm creating/consuming are built in the same web project (for good or for bad, not my design, I'm still learning).  Unfortunately I don't think I can use this suggestion as I don't have any assemblies in the bin to use, or so I don't think I do.

     

  • Re: trying to register my controls in web.config

    06-12-2007, 11:59 AM
    Answer
    • Loading...
    • mosessaur
    • Joined on 07-11-2002, 6:40 PM
    • Cairo
    • Posts 352

    Then use this:

    <pages>
      <
    controls>
        <add namespace="MyControls" tagPrefix="ctrl"/>  
    </controls>
    </
    pages>

    Just make sure that you have a namespace to your controls. Your controls should be located in App_Code folder.
    Or you can post your controls code so we can help you if this didn't resolve your issue

    Muhammad M. Mosa Soliman
    Software Engineer
    Moses's Blog
  • Re: trying to register my controls in web.config

    06-27-2007, 11:34 AM
    • Loading...
    • Flip
    • Joined on 05-24-2007, 9:57 AM
    • Posts 3

    Hi, thank you for your reply.  My main proplem with this, is my control's code, isn't in the App_Code directory, it's in the web project itself in a Controls directory.  That is how my boss structured things, so I don't think I can change this without being able to convince him this is wrong.  I wish I could post my code here, but it's proprietary. :<

     

    Are you able to put controls into your web project and register them this way?

     

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter