Page view counter

Latest release has problem with custom controls w/ParseChildren(false)...?

Rate It (1)

Last post 10-30-2007 8:22 PM by danielflippance. 9 replies.

Sort Posts:

  • Latest release has problem with custom controls w/ParseChildren(false)...?

    04-30-2006, 1:55 PM
    • Loading...
    • drub0y
    • Joined on 08-21-2003, 11:40 AM
    • NYC, NY
    • Posts 26

    Generation of designer file failed: Type 'System.Web.UI.UserControl' does not have a public property named 'mimformationItem'.

    First, I was able to successfully convert this same web site with the last version without problems. Second, as a disclaimer, this may not be a problem with just WAP, but considering it's ability to parse it last version and it's inability to do so in the latest version, it's definitely related.

    The control causing the error is an ASCX and on the code-behind class I'm using [ParseChildren(false)] and handling AddParsedSubObject to do some custom handling of controls. The controls being added are also custom ASCX controls, but at that point it really shouldn't matter. It works 100% at runtime, so maybe I just don't have the right design time attributes on my control, but this definitely did convert successfully last version.

    The source view has no "squiggles" indicating errors so it seems to be respecting the ParseChildren(false) (if I remove it, I get "squiggles"). Also, if I try and open files that use this control pattern in the designer, I get a designer error... but it opens with the little gray error box (screenshot here).

    FWIW, I checked myself against MSDN's docs and Nikhil's post on ASP.NET 2.0 designer features here. If anyone has any suggestions I'd love to hear them. In the end this isn't that big a deal since I don't really have to convert to the designer separated files, but it would be nice. ;)

    Thanks,
    Drew

    Chief Software Architect
    Mimeo.com, Inc. - http://www.mimeo.com
  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    05-02-2006, 1:35 PM
    • Loading...
    • timmcb
    • Joined on 11-04-2002, 4:29 PM
    • Redmond, WA
    • Posts 469
    • AspNetTeam

    Most likely the problem occurs because the field generator is unable to get the correct type of your user control.  This occurs when it can not resolve the src in the register directive to the physical location on disk.  Usually, this is because it is not understanding your application root and assuming it is the project root.  You can use the Web property page to set the application root to something other than the project if you are using IIS.  Another cause is having sub virtual directories in the site.  The next version of Web Application Projects will handle sub virtual directories.

    This may have worked in previous versions of Web application projects because we were not looking at child properties.

    Can you post an example page and user control and explain your project structure with regards to where these files are located?

    Tim McBride

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    05-03-2006, 10:40 PM
    • Loading...
    • drub0y
    • Joined on 08-21-2003, 11:40 AM
    • NYC, NY
    • Posts 26

    Tim,

    Hey, thanks for the reply. I don't know if it's related to the things you mentioned. I came up with the simplest possible repro for the problem and have posted the sample project for you guys to check out here. It's all set up so all you have to do is right click the WebForm1.aspx and try and convert it.

    HTH,
    Drew

    Chief Software Architect
    Mimeo.com, Inc. - http://www.mimeo.com
  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    05-04-2006, 12:07 PM
    • Loading...
    • timmcb
    • Joined on 11-04-2002, 4:29 PM
    • Redmond, WA
    • Posts 469
    • AspNetTeam

    Thanks, that is a big help.  I'll try it out today.

    Tim McBride

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    05-04-2006, 1:41 PM
    • Loading...
    • timmcb
    • Joined on 11-04-2002, 4:29 PM
    • Redmond, WA
    • Posts 469
    • AspNetTeam

    I took a look at the project and I see what is going on.  If I build the project it converts correctly.  If I don't build the project I get the error you describe.  To read the ParseChildrenAttribute the ASP.Net parser uses reflection.  When the user control is not compiled the parser is unable to get a Type for your user control.  So, instead it uses the generic UserControl type.  Of course reflection on this type will not have your attributes and the parser gets confused.

    Anyway, I think you can work around the problem by first compiling your project.  I'm sure your project is not nearly as simple as this one so there could be more going on.  If your user controls are in a different project than your page make sure the "Override Application URL"  property is set correctly in each project so that "~/" app relative paths in register directives can be resolved correctly.  Also, make sure the user control project is referenced and built.  This should allow the user control types to be properly resolved.

    Tim McBride

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    05-04-2006, 2:48 PM
    • Loading...
    • drub0y
    • Joined on 08-21-2003, 11:40 AM
    • NYC, NY
    • Posts 26

    Hmmm... actually I *did* compile first because I figured that might have been the problem originally and makes sense that you'd have to do that.

    So, I went back to the repro project, cleaned and recompiled just to make sure and then tried to open it in the designer and still get the error. Is it possible you're running a newer build than RC1 and something has been fixed?

    FWIW, my control is in the same project (thus the same assembly). I was referencing with ~/, but even if I change to a relative path I get the same problem. I'm willing to do a little app sharing action if you want to get a look at the whole setup here on my side.

    Cheers,
    Drew

    Chief Software Architect
    Mimeo.com, Inc. - http://www.mimeo.com
  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    05-04-2006, 5:05 PM
    • Loading...
    • timmcb
    • Joined on 11-04-2002, 4:29 PM
    • Redmond, WA
    • Posts 469
    • AspNetTeam
    Thanks Drew.  Yes, It could have been fixed in my build.  Send me (timmcb) an e-mail @microsoft.com and I'll reply with an ftp site where you can send me your app.
    Tim McBride

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    03-28-2007, 9:15 AM
    • Loading...
    • CTGuy67
    • Joined on 06-24-2002, 7:16 AM
    • Posts 43

    I'm getting this same error...were you guys able to resolve this, and if so what was the conclusion?

    Thanks
    Steve

  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    07-03-2007, 2:58 PM
    • Loading...
    • rodrigoelp
    • Joined on 06-29-2007, 3:47 PM
    • Posts 5

     

    Erm, I would like to know if you guys could resolve this problem.

    Currently I am having the same issue, my control is a little different than the proposed in the topic, but I am having the same error message and I have tried almost everything (obviously not the right things.)

    My problem is described next:

    I am having a custom UserControl with a generic list containing class instances of a class I made. The UserControl also has the ParseChildren attribute with the parsing flag on true and the default property named to my List of elements.

    When I write the control tag name everything is ok, the intellisense shows everything and compiles ok. In fact my only problem is when I switch back to design mode getting the “Type ‘System.Web.UI.UserControl’ does not have a property named ‘ObjectListItem’” which is the class’ name of the item stored within the generic list.

    This is a big issue for me because the designers are complaining about the page layout when trying to edit anything or just move the controls. And i would like to know if theres a workaround or what i am doing wrong to correct it as fast as possible. Thanks.

     

     Here is the source code sample where you can reproduce the error:
     

    This is the element code which will contain the information. 

    1    //Item to store within the UserControl.
    2    namespace CustomControls
    3 {
    4 public class MyItem
    5 {
    6 private string m_Name;
    7 public string Name
    8 {
    9 get { return m_Name; }
    10 set { m_Name = value; }
    11 }
    12 }
    13 }

     

    This is the Custom web UserControl code behind. 

     
    1    using System;
    2 using System.Data;
    3 using System.Configuration;
    4 using System.Collections;
    5 using System.Web;
    6 using System.Web.Security;
    7 using System.Web.UI;
    8 using System.Web.UI.WebControls;
    9 using System.Web.UI.WebControls.WebParts;
    10 using System.Web.UI.HtmlControls;
    11 12 using System.Collections.Generic;
    13 using CustomControls;
    14 15 [ParseChildren(true, "ItemList")]
    16 [PersistChildren(false)]
    17 [PersistenceMode(PersistenceMode.InnerProperty)]
    18 public partial class controls_MyWebUserControl : System.Web.UI.UserControl
    19 {
    20 private List m_Items = new List();
    21 public List ItemList //this is the element not found by the designer. 22 {
    23 get { return m_Items; }
    24 }
    25 protected void Page_Load(object sender, EventArgs e) { }
    26 27 protected override void CreateChildControls()
    28 {
    29 if (this.DropDownList1.Items.Count != ItemList.Count)
    30 {
    31 for (int i = 0; i < ItemList.Count; i++)
    32 {
    33 this.DropDownList1.Items.Add(new ListItem(ItemList[i].Name, ItemList[i].Name));
    34 }
    35 }
    36 base.CreateChildControls();
    37 }
    38 protected void Button1_Click(object sender, EventArgs e){ }
    39 }
     
    This is the UserControl ascx.
    1    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyWebUserControl.ascx.cs" Inherits="controls_MyWebUserControl" %>
    2 <-asp:Label "Label1" runat="server" Text=""> 3 <-asp:TextBox "TextBox1" runat="server"> 4 <-asp:DropDownList "DropDownList1" runat="server"><%-- I had to add a line between the asp flag to avoid the tool from removing it. --%>
    5 6 <-asp:Button "Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    Code in the aspx page where i want the control with some parameters. There is no need to add extra code behind to the page except the one auto generated by vs.
    1    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    2 <%@ Register TagPrefix="custom" Namespace="CustomControls" %>
    3 <%@ Register src="~/controls/MyWebUserControl.ascx" TagName="MyWebUserControl" TagPrefix="custom" %>
    4 "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 5 <-html xmlns="http://www.w3.org/1999/xhtml"> 6 <-head runat="server">
    7 <-title>Test Page
    8 <-/head>
    9 <-body>
    10 <-form id="form1" runat="server">
    11 <-asp:ScriptManager ID="ScriptManager1" runat="server" />
    12 <-div>
    13 <-custom:MyWebUserControl ID="xx1" runat="server">
    14 <-custom:MyItem Name="Item name 1" />
    15 <-custom:MyItem Name="Item name 2" />
    16 <-custom:MyItem Name="Item name 3" />
    17 <-custom:MyItem Name="Item name 4" />
    18 <-/custom:MyWebUserControl>
    19 <-/div>
    20 <-/form>
    21 <-/body>
    22 <-/html>
     
    Compile and switch to design mode in the default.aspx page (or anyone that you may have done containing the UserControl). 
    Thanks in advance.
     

     

    --
    Rodrigo Landaeta
  • Re: Latest release has problem with custom controls w/ParseChildren(false)...?

    10-30-2007, 8:22 PM

    FYI:  I have noticed that when I convert a Web Site project using the Visual Studio "Convert to web application" menu item, half of the pages in the site are converted and half are not.  The difference seems to be that the ones that do not convert have a control on them which is a TemplateContainer (ie, it has a public property of type ITemplate marked with the attribute [TemplateContainer].  If I comment out this control in the .ASPX file, then choose "Convert to web application" again, the .Designer file is now generated.  When I uncomment the control in the aspx, eveything is fine.

    Here's the control that causes the problem for me:

     <iep:NextStepControl ID="next" runat="server" >
      <ContentTemplate>
          <ul>
            <li>... blah blah </li>
       </ul>
      </ContentTemplate>
     </iep:NextStepControl>

    So, steps are:

    - surround control with <%--      --%>  in .aspx
    - Click "Convert to web application" again.
    - remove the <%--      --%> and recompile.

    Cheers,

    Dan

Page 1 of 1 (10 items)
Microsoft Communities