You're right, it may not be a bug, after all. Though I have read of several
people having this same problem, and have never read where anyone has solved
the problem, I am beginning to think that is is an expected behavior, under
the circumstances. The scenario goes like this.
I have the following three classes:
MyControl : System.Web.UI.WebControls.WebControl
MyChildObject
and
MyChildCollection : CollectionBase
MyControl has a public property, ChildCollection, of type MyChildCollection
which holds objects of type MyChildObject. MyChildObject has a public
property, URL, which needs to hold a URL string that is preferably, but not
necessarily, relative to the page that hosts MyControl.
I place MyControl on the Page and when I select the control in the designer
and then click the ChildCollection property I get a collection editor
UITypeEditor as desired.
The problem occurs when I try to use any UrlEditor (UrlEditor, XmlUrlEditor,
XslUrlEditor) as the UITypeEditor for the URL property in the MyChildObject
class. If, in the collection editor, I click to edit the URL property of
the instance of MyChildObject, the desired result is to get a UrlEditor
associated with the URL of my project. What I get, instead, is an error
"Object reference not set to an instance of an object" with no clue given
where the error is occuring or what object reference is not set.
I have continued to work on the problem and think I am on the right track.
The problem seems to be that the UrlEditor requires an IComponent or an
ISite in order to associate the Page with the control. The first control is
sited on the Page, and gets its ISite from the Page. The next level of
control should get its ISite from the first control, which got it from the
Page. If I understand correctly, the problem is that there is a break in
the site lineage because the MyChildObject is in a collection rather than a
direct descendent of MyControl..
I now believe that the solution will have something to do with implementing
IComponent and/or ISite in MyChildObject and somehow connecting that ISite
back to the Page. Possible routes seem to be to implement one of, or some
combination of, IContainer, ISite, and IComponent in MyControl or perhaps to
implement one or more of them in my MyChildCollection.
If there is anyone out there with more knowledge or understanding than I
have about using ISite, IComponent, Control, and IContainer, I would
appreciate any suggestions about how to get the Component from my Page to
MyChildObject, or any other suggestions how to solve this dilemma.
Regards,
Dale Preston
MCAD, MCDBA, MCSE