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

Discussion in 'ASP .Net' started by Allan Ebdrup, Jul 16, 2007.

  1. Allan Ebdrup

    Allan Ebdrup Guest

    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, Jul 16, 2007
    #1
    1. Advertising

  2. Allan Ebdrup

    Allan Ebdrup Guest

    I got it to work, some problem with refreshing the dll, i deleted the
    reference and added it again and it worked.
    Allan Ebdrup, Jul 16, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hessam
    Replies:
    0
    Views:
    2,161
    Hessam
    Aug 8, 2003
  2. =?Utf-8?B?UmFqZXNoIHNvbmk=?=

    'System.String[]' from its string representation 'String[] Array'

    =?Utf-8?B?UmFqZXNoIHNvbmk=?=, May 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,782
    =?Utf-8?B?UmFqZXNoIHNvbmk=?=
    May 4, 2006
  3. Apple
    Replies:
    3
    Views:
    290
    Apple
    Aug 1, 2005
  4. Hessam
    Replies:
    1
    Views:
    220
    Teemu Keiski
    Aug 16, 2003
  5. Hessam
    Replies:
    0
    Views:
    258
    Hessam
    Aug 8, 2003
Loading...

Share This Page