Cannot create an object of type 'CustomWizard' from its string representation...

A

Allan Ebdrup

I get the error:

"Cannot create an object of type 'CustomWizard' from its string
representation 'CustomWizard1' for the CustomWizard Property."

when I view my custom server web control in design view. Everything runs
fine when I run the page, it's only design view that gives the error.
My custom server web control is inherited form the wizard control.

In OnInit I add a Child to the wizard, witch is also a custom server web
control I've created (a header in the wizard)

On the child control I've added a "CustomWizard" property in whitch I set
the Wizard control that the Child is a Child of (the header knows what
wizard it's part of).
Now I get the following error in design view:

"Cannot create an object of type 'CustomWizard' from its string
representation 'CustomWizard1' for the CustomWizard Property."

I guess it's because of some kind of serialization or something so I've
added the following attributes to tha CustomWizard property in the child
control:

[System.ComponentModel.Browsable(false)]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]

But that didn't solve the problem.

Can't you add properties to controls and only use them programatically? What
am I missing?

I've tried adding a typeconverter:
----------------
public class PageControlTypeConverter<TControl> : TypeConverter where
TControl : Control
{
// Overrides the CanConvertFrom method of TypeConverter.
// The ITypeDescriptorContext interface provides the context for the
// conversion. Typically, this interface is used at design time to
// provide information about the design-time container.
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
// Overrides the ConvertFrom method of TypeConverter.
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is string)
{
Page page = (Page)HttpContext.Current.Handler;
TControl c = page.FindControl((string)value) as TControl;
return c;
}
return base.ConvertFrom(context, culture, value);
}
// Overrides the ConvertTo method of TypeConverter.
public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
return ((TControl)value).ID;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
----------------
And adding this attribute to the child controls property:
[TypeConverter(typeof(PageControlTypeConverter<CustomWizard>))]

But I still get the same error in design view...

Is ther any way to debug the code run to generate design view?

Any help would be much appreciated.

Kind Regards,
Allan Ebdrup
 
A

Allan Ebdrup

I got it to work, some problem with refreshing the dll, i deleted the
reference and added it again and it worked.
 

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

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top