Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Allan Ebdrup - 16 Jul 2007 11:56 GMT
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
Allan Ebdrup - 16 Jul 2007 13:06 GMT
I got it to work, some problem with refreshing the dll, i deleted the
reference and added it again and it worked.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.