Error creating control: ID property is not specified

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

  1. Allan Ebdrup

    Allan Ebdrup Guest

    I get the error "Error creating control: ID property is not specified" when
    I view my custom web control in design view.
    I add the control that gives an error in OnInit like this:
    -----
    foreach (WizardStep ws in WizardSteps)
    {
    CustomWizardStepHeader header = new CustomWizardStepHeader();
    header.ID = "CustomWizardStepHeader";
    ws.Controls.AddAt(0, header);
    }
    -----
    So I have specified the ID, why do I get the error then?

    Kind Regards,
    Allan Ebdrup
     
    Allan Ebdrup, Jul 13, 2007
    #1
    1. Advertising

  2. Hi Allan,

    Is your custom web control a User Control or a Server Control? I assume
    you're creating a custom Server Control which inherits from the Wizard
    control. When you use this customer Server Control on a Web Form, you will
    also need to assign the ID property for it. For example:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
    Inherits="_Default" %>
    <%@ Register TagPrefix="c" Namespace="myns" Assembly="__code" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    <c:Class1 runat="server"></c:Class1>
    </div>
    </form>
    </body>
    </html>


    Above code will report error "Error creating control ID property is not
    specified" if you switch to the designer, you will need to change to:

    <c:Class1 runat="server" ID="c1"></c:Class1>


    I hope I haven't misunderstood anything, in that case, please post more
    about your code. Thanks.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jul 16, 2007
    #2
    1. Advertising

  3. Allan Ebdrup

    Allan Ebdrup Guest

    "Walter Wang [MSFT]" <> wrote in message
    news:sOMy%...
    > Hi Allan,
    >
    > Is your custom web control a User Control or a Server Control? I assume
    > you're creating a custom Server Control which inherits from the Wizard
    > control.


    Yes it's a server control.

    > When you use this customer Server Control on a Web Form, you will
    > also need to assign the ID property for it. For example:

    <snip>

    There is an ID assigned to the tag, and everything runs fine when I run the
    page, the problem only occurs in design view.
    I've added IDs to all the controls that are generated programatically and
    now I get a different error (again only in design view not when I run the
    page)
    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?

    Kind Regards,
    Allan Ebdrup
    --
    Try a beta of my free Survey solution that makes heavy use of AJAX at
    http://obsurvey.com, feedback is very welcome.
     
    Allan Ebdrup, Jul 16, 2007
    #3
  4. Allan Ebdrup

    Allan Ebdrup Guest

    Cannot create an object of type 'CustomWizard' from its string representation (was:Re: Error creating control: ID property is not specified)

    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...
     
    Allan Ebdrup, Jul 16, 2007
    #4
  5. RE: Cannot create an object of type 'CustomWizard' from its string representation (was:Re: Error creating control: ID property is not specified)

    Hi Allan,

    I'm not sure if this is caused by the TypeConverter or not. I cannot tell
    clearly what might be the cause without reproducing the issue on my side
    and see the detailed error messages. Could you please create a reproducible
    project and send it to me? Thank you for the trouble.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jul 17, 2007
    #5
  6. Allan Ebdrup

    crashkiwi

    Joined:
    Jun 30, 2009
    Messages:
    1
    Location:
    Napier Hawkes Bay
    Maybe

    i know its simple but i managed to recreate the same error

    if your user control also has a form element rename its ID
    or remove it completely ....
    there are two HTML elements rendered in the parent web form (or page if you prefer) with the same control type and name removing the form element from the web control should fix the issue


    ie
    Code:
    [COLOR="DarkSlateBlue"
    somepage.aspx
    ]
    <%@ Register TagPrefix="uc1" Namespace="myns" Assembly="__code" %>
    <html xmlns=" Standard reference" >
    <head runat="server">
        <title></title>
    </head>
    <body>
     <form id="form1" runat="server"> 
        <uc1:MD5hasher ID="MD5hasher1" runat="server" Visible="true">
        </uc1:MD5hasher>
     </form>
     </body>
    </html>[/COLOR]
    
    and [COLOR="DarkRed"]usercontrol.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MD5hasher.ascx.cs" Inherits="UNLEASHED.MD5hasher" %>
    <html>
    <head></head>
    <body>
    <h1> Generate a MD5 Hash</h1>
        <div align="center">
           <h2>Enter Text to Hash (Please)</h2>
           <br />
           <asp:TextBox runat="server" ID="Subject" Height="100" Width="400" TextMode="MultiLine" />
           <br />
            <br />
           <asp:Button runat="server" ID="HasherButton" Text="Create Hash" 
                onclick="HasherButton_Click" />
           <br />
           <asp:Label runat="server" ID="OutputLabel" visible="false" Font-Bold="true" />
        </div>
    </body>
    </html>[/COLOR]
    
    should fix the issue and should render in the designer...
     
    crashkiwi, Jun 30, 2009
    #6
    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. ~~~ .NET Ed ~~~
    Replies:
    0
    Views:
    942
    ~~~ .NET Ed ~~~
    Nov 10, 2004
  2. Anabela Silva
    Replies:
    0
    Views:
    1,234
    Anabela Silva
    Nov 1, 2006
  3. Nathan Sokalski
    Replies:
    5
    Views:
    439
    Nathan Sokalski
    Aug 7, 2008
  4. ~~~ .NET Ed ~~~
    Replies:
    0
    Views:
    200
    ~~~ .NET Ed ~~~
    Nov 10, 2004
  5. Nathan Sokalski

    C# says Error Creating Control when no ID is specified

    Nathan Sokalski, Aug 4, 2008, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    220
    Nathan Sokalski
    Aug 7, 2008
Loading...

Share This Page