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.