[Mono-bugs] [Bug 71815][Maj] New - ASP.NET Data-bound template incompatible behavior
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Wed, 26 Jan 2005 16:32:42 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by m@pernecky.sk.
http://bugzilla.ximian.com/show_bug.cgi?id=71815
--- shadow/71815 2005-01-26 16:32:42.000000000 -0500
+++ shadow/71815.tmp.28910 2005-01-26 16:32:42.000000000 -0500
@@ -0,0 +1,155 @@
+Bug#: 71815
+Product: Mono: Class Libraries
+Version: 1.0
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Major
+Component: Sys.Web
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: m@pernecky.sk
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: ASP.NET Data-bound template incompatible behavior
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+Mono gets wrong container type in data-bound templates. (Wrong=Different
+that MS framework). When defining a template in class
+(public class TemplatedControl : WebControl)
+
+ [TemplateContainer (typeof (SomeTemplateItemClass))]
+ public virtual ITemplate ItemTemplate
+ {
+ get { return m_ItemTemplate; }
+ set { m_ItemTemplate = value; }
+ }
+
+Mono retrieves the type TemplateControl instead of SomeTemplateItemClass as
+does MS. This is clearly wrong, since the attribute TemplateContainer
+determines the type of template.
+
+The error is in class System.Web.Compilation.TemplateControlCompiler in
+method GetContainerType. There can be clearly seen that Mono determines the
+type based on attribute "Items" of the parent class (e.g. TemplatedControl)
+and not on the value of the TemplateContainerAttribute.
+
+Steps to reproduce the problem:
+1. Create assembly with these classes:
+using System;
+using System.ComponentModel;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+
+namespace Test
+{
+ public class MyTemplateItem : Control, INamingContainer
+ {
+ private string m_Property;
+
+ public MyTemplateItem (string value)
+ {
+ m_Property = value;
+ }
+
+ public virtual string Property
+ {
+ get { return m_Property; }
+ set { m_Property = value; }
+ }
+ }
+
+ [ParseChildren(true)]
+ [PersistChildren(false)]
+ public class TemplatedControl : Control, INamingContainer
+ {
+ private ITemplate m_ItemTemplate;
+ private object m_Data;
+ private string[] m_Items;
+
+ public override ControlCollection Controls
+ {
+ get
+ {
+ EnsureChildControls ();
+ return base.Controls;
+ }
+ }
+
+ [TemplateContainer (typeof (Puco.Test.MyTemplateItem))]
+ public virtual ITemplate ItemTemplate
+ {
+ get { return m_ItemTemplate; }
+ set { m_ItemTemplate = value; }
+ }
+
+ public object DataSource
+ {
+ get { return m_Data; }
+ set { m_Data = value; }
+ }
+
+ public override void DataBind ()
+ {
+ m_Items = (string[]) m_Data;
+ }
+
+ protected override void CreateChildControls ()
+ {
+ Controls.Clear ();
+
+ if (m_Items != null)
+ {
+ for (int i=0; i<m_Items.Length; i++)
+ {
+ MyTemplateItem c = new MyTemplateItem (m_Items [i]);
+ ItemTemplate.InstantiateIn (c);
+ Controls.Add (c);
+ }
+ }
+
+ ChildControlsCreated = true;
+ }
+ }
+}
+
+2. Create a web form using this assembly:
+
+<%@ Page Language="C#" %>
+<%@ Register TagPrefix="t" Assembly="Test" Namespace="Test" %>
+
+
+<t:TemplatedControl runat="server" id="Ctrl">
+<ItemTemplate>
+ <%# Container.Property %>
+</ItemTemplate>
+</t:TemplatedControl>
+
+<script runat="server">
+
+protected override void OnLoad (EventArgs e)
+{
+ Ctrl.DataSource = new string[] { "string1", "string2", "string3" };
+ Ctrl.DataBind ();
+ base.OnLoad (e);
+}
+
+</script>
+
+Actual Results:
+The ASP.NET compiler returns an error stating that control Test.
+TemplatedItem doesn't have property "Property".
+
+Expected Results:
+The expceted result would be: string1 string2 string3 without any errors
+
+Additional Information:
+Before checking the returning type for "Items" property, the value of the
+TemplateContainerAttribute should be checked with: Attribute.
+GetCustomAttribute (<property>, typeof (TemplateContainerAttribute), false)
+and than checked if the type implements INamingContainer.