I’ve been fighting an odd problem today with a custom control I’m building. The control is another extender control that has a number of child items that track other items on the form. The markup looks something like this:
<ww:LocalizationExtender id="Localizer" runat="server">
<LocalizationItems>
<ww:LocalizationItem ControlId="lblMessage"
Property="Text" runat="server"
EnableLocalization="true"
LocalizationType="GlobalString">
</ww:LocalizationItem>
<ww:LocalizationItem ControlId="btnSubmit"
Property="Text"
EnableLocalization="true"
LocalizationType="GlobalString">
</ww:LocalizationItem>
</LocalizationItems>
</ww:LocalizationExtender>
The logic in the control works fine at runtime. But when the control renders I get this error display:

Haeh? The problem is that LocalizationItems is a collection and it doesn’t have a LocalizationExtender property and well nothing of the sort gets set on LocalizationItems or the child items. Something isn’t wired right but I can’t figure out what the heck it is. I compared with other controls that have this same setup and it all looks right, but it looks that the designer is very unhappy.
It seems like an attribute mismatch, but I can’t see it in the code.
[ToolboxData("<{0}:LocalizationExtender runat=server />")]
//[ProvideProperty("LocalizationItem", typeof(Control))]
[NonVisualControl, Designer(typeof(LocalizationExtenderDesigner))]
[ParseChildren(true, "LocalizationItems")]
[PersistChildren(false)]
//[DefaultProperty("LocalizationItems")]
//[DefaultEvent("ValidateControl")]
public class LocalizationExtender : Control //, IExtenderProvider
{
private new bool DesignMode = HttpContext.Current == null;
/// <summary>
/// A collection of the individual Localization Items for the control
/// that track each of the controls on the page that are localized.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Browsable(true)]
public LocalizationItemCollection LocalizationItems
{
get { return _Items; }
set { _Items = value; }
}
private LocalizationItemCollection _Items = new LocalizationItemCollection();
The collection just inherits from CollectionBase. I get the same error if I replace the manual collection with a List<LocalizationItem> - in fact I created the manual collection because of this damn error since this is the only difference I see between this control and another.
If take the child items out of the page, the control renders fine. If leave just the collection in place it too renders fine. But as soon as a child item is added into the collection in the designer it fails. The designer will let me add items visually and persist them fine. However, once I switch into markup and then back to the designer the control is hosed again.
I’ve tried to debug into this and see if I can capture the code failing somewhere, but even attached to the debugger into a second instance in VS I can’t find the spot that’s a problem. The main control OnInit() fires fine, but beyond that I get nothing. No collection or item constructors (presumably because they’re deserializing somehow) – nothing to hook code to and the debugger is not throwing exception dialogs either…
I’m stumped and I’m out of ideas on how to track this down… Anybody have any ideas? I need a little push <g>…
Other Posts you might also like