Error creating control: ID property is not specified

A

Allan Ebdrup

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);
}
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
A

Allan Ebdrup

Walter Wang said:
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
 
A

Allan Ebdrup

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);
}
}
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
Joined
Jun 30, 2009
Messages
1
Reaction score
0
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...
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top