Incorrect type generated with User Controls registered in web.config

Last post 05-28-2009 12:42 AM by neha_flower_2003. 8 replies.

Sort Posts:

  • Incorrect type generated with User Controls registered in web.config

    05-10-2006, 10:40 AM
    • Member
      25 point Member
    • SelfishGene
    • Member since 05-10-2006, 2:06 PM
    • Posts 5
    When we register our User Controls in web.config instead of on the page, we found the type is generated as System.Web.UI.UserControl instead of the type of the actual user control. Here are the steps to reproduce this problem:

    1) Create a new Web Site
    2) Create a folder called Controls and add a user control to this folder (e.g., WebUserControl.ascx)
    3) Add a web.config to the site
    4) Add the control registration to the web.config. E.g.:

      <pages>
       <controls>
        <add tagPrefix="test" tagName="WebUserControl" src="~/Controls/WebUserControl.ascx"/>
       </controls>
      </pages>

    5) Add an instance of the user control to default.aspx:

            <test:WebUserControl runat="server" ID="test" />

    6) Add a Web Application Project to the solution. Delete default.aspx and web.config from the new project. Copy the Controls folder, Default.aspx, and web.config to the new project.

    7) Right click on the new Web Application project and select "Convert To Web Application"

    8) Take a look at Default.aspx.designer.cs. We expect to see:

        protected Controls_WebUserControl test;

      But instead we get:

        protected System.Web.UI.UserControl test;

    Let's try moving the control registration to the page itself.
     
    9) Remove the "pages" section from the web.config

    10) Add the control registration to default.aspx:

    <%@ Register TagPrefix="test" TagName="WebUserControl" Src="~/Controls/WebUserControl.ascx" %>

    11) Delete Default.aspx.designer.cs. Right click Default.aspx and select "Convert to Web Application"

    12) Take a look at Default.aspx.designer.cs. We get what we expected:

         protected Controls_WebUserControl test123;

    So basically whenever we register controls in our web.config, we get the wrong type in the .designer.cs file. In our project we have a number of commonly used controls registered in web.config so unless there is a workaround or fix, we cannot use WAP. I should mention that I tried many different variations on the path for the src attribute ("/", "~/", "./", etc).

    Please let me know if there is a solution for this. Thanks.

  • Re: Incorrect type generated with User Controls registered in web.config

    05-10-2006, 7:59 PM
    • Contributor
      2,365 point Contributor
    • timmcb
    • Member since 11-04-2002, 4:29 PM
    • Redmond, WA
    • Posts 469
    • AspNetTeam
    Thanks for the bug report.  I can see the problem in the code.  We are reading the register directives out of config but not converting the type when it is a user control.  I'll try to fix it for the VS 2005 service pack.
    Tim McBride

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Incorrect type generated with User Controls registered in web.config

    07-06-2006, 11:27 PM
    • Member
      25 point Member
    • SelfishGene
    • Member since 05-10-2006, 2:06 PM
    • Posts 5
    Is there anyway to get a fix for this earlier? We have a large site that is painfully slow without WAP but uses a lot of controls... we really need to move to WAP but register user controls in web.config.
  • Re: Incorrect type generated with User Controls registered in web.config

    09-06-2006, 7:30 PM
    • Member
      25 point Member
    • SelfishGene
    • Member since 05-10-2006, 2:06 PM
    • Posts 5

    It's been many months and still no fix to this problem. I was wondering why hasn't this been added to the "FAQ and Known Issues" list?

  • Re: Incorrect type generated with User Controls registered in web.config

    09-13-2006, 8:41 PM
    • Contributor
      2,365 point Contributor
    • timmcb
    • Member since 11-04-2002, 4:29 PM
    • Redmond, WA
    • Posts 469
    • AspNetTeam
    Sorry, we have not been good at updating the FAQ.  I'll forward the request to the program manager in charge of web application projects.  The only way to get the fix before SP1 is to contact Microsoft product support and request a hot fix for the problem.
    Tim McBride

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Incorrect type generated with User Controls registered in web.config

    10-04-2006, 12:40 PM
    • Member
      346 point Member
    • chadly
    • Member since 06-26-2005, 9:39 PM
    • Posts 70

    Tim,

     I just downloaded the VS 2005 SP1 Beta and it appears this problem is still happening in WAP.
     

  • Re: Incorrect type generated with User Controls registered in web.config

    10-04-2006, 1:50 PM
    • Contributor
      2,365 point Contributor
    • timmcb
    • Member since 11-04-2002, 4:29 PM
    • Redmond, WA
    • Posts 469
    • AspNetTeam

    The scenario as originally described was fixed and verified in the SP1 beta.  I just reverified it as well.  Your scenario must be different somehow.  Where is your .ascx on disk relative to your page?  What does your config registration look like for the user control?  Are you using IIS or the VS Web Server?

    Tim McBride

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Incorrect type generated with User Controls registered in web.config

    10-05-2006, 8:40 PM
    • Member
      346 point Member
    • chadly
    • Member since 06-26-2005, 9:39 PM
    • Posts 70
    Ah, nevermind.  When I opened my previously created WAP, the old control declarations were still declared as UserControl, but when I add a new one to the page, it fixes all the declarations.  Its all gravy now.
  • Re: Incorrect type generated with User Controls registered in web.config

    05-28-2009, 12:42 AM

     

    Dear sir, I dont want to add refrence of user controls neighter in aspx page nor web.congf file, then how can  I load user control dynamically.

     

    plz sir replying me ASAP (very urgent)

    thanks with regards

Page 1 of 1 (9 items)