Jonathan Crossland
Posts: 630
Nickname: jonathanc
Registered: Feb, 2004
Jonathan Crossland is a software architect for Lucid Ocean Ltd
ImageURLEditor Answer
Posted: Mar 10, 2004 6:21 PM
This post originated from an RSS feed registered with .NET Buzz
by Jonathan Crossland.
Original Post: ImageURLEditor Answer
Feed Title: Jonathan Crossland Weblog
Feed URL: http://www.jonathancrossland.com/syndication.axd
Feed Description: Design, Frameworks, Patterns and Idioms
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Jonathan Crossland
Latest Posts From Jonathan Crossland Weblog
Advertisement
To implement and use the ImageUrlEditor on a class that does not implement IComponent (which could be any custom class not on the initial webcontrol interface ) - you must create one yourself.
In my case I have a Collection of ImageOverItem and an ImageURL on the class. The standard ImageURLEditor will always fail, as the Site is not available.
It is really simple to get around: here is the code as I have it in a control I am writing.
I add the EditorAttribute
[ Editor( typeof ( ControlLib. Design. ImageOverItemEditor) , typeof ( UITypeEditor) ) ]
on my ImageURL property, which points to the class below.
using System;
using System. Web. UI. Design;
using System. Drawing. Design;
using System. ComponentModel;
namespace ControlLib. Design
{
public class ImageOverItemEditor : UITypeEditor
{
string _Caption = "Select Image" ;
string _Filter = "Image Files(*.gif;*.jpg;*.jpeg;*.bmp;*.wmf;*.png)|*.gif;*.jpg;*.jpeg;*.bmp;*.wmf;*.png|All Files(*.*)|*.*|" ;
UrlBuilderOptions _Options = UrlBuilderOptions. NoAbsolute;
public ImageOverItemEditor( )
{
}
public override object EditValue( ITypeDescriptorContext context , IServiceProvider provider , object value )
{
if ( provider ! = null )
{
object item = null ;
string url = "" ;
if ( context . Instance is ImageOverItem)
item = ( ( ImageOverItem) context . Instance) . Parent;
if ( ( item ! = null ) & & ( item is IComponent) )
{
url = UrlBuilder. BuildUrl( ( IComponent) item , null , ( string ) value , _Caption , _Filter , _Options ) ;
if ( url ! = null )
{
return url ;
}
}
}
return "" ;
}
}
}
You need to have access to the Parent from the class, I have a Parent property set inside my Collections Add.
Read: ImageURLEditor Answer