Accessing path in a custom designer

D

Dale Preston

I am creating a custom web control with a custom property editor. The
custom editor is for setting a relative URL property of an item in a
collection property of the control. Because the property is a collection,
the UrlEditor will not work because of a known (even if not confessed) bug
in all UITypeEditors that derive from UrlBuilder.

How I can determine, within the EditValue method of my custom UITypeEditor,
what the relative URL path of my project is, similarly to the way the
UrlEditor does?

Dale Preston
MCAD, MCDBA, MCSE
 
R

recoil

I am unsure of the bug you are stating of but perhaps you could
instantiate a UrlBuilder and merely use the UrlBuilder to get the
relative url path. There is also the line thinking where you enumerate
of the project members and then finding a project item that contains
the information you need.
 
D

Dale Preston

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top