C# says Error Creating Control when no ID is specified

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

When using C# for a codebehind language, Design View displays the error
message "Error Creating Control - ctrl type ID property is not specified"
and does not allow you to select the control in Design View. Since it is not
required that an ID is specified (I know that it is needed in order to do
many things, but it is not required for a simple Label with a Text property
that doesn't change, for example), I find this very frustrating. VB.NET does
not display this error, so why is C# displaying it? Thanks.
 
I

Ignacio Machin ( .NET/ C# MVP )

When using C# for a codebehind language, Design View displays the error
message "Error Creating Control - ctrl type ID property is not specified"
and does not allow you to select the control in Design View. Since it is not
required that an ID is specified (I know that it is needed in order to do
many things, but it is not required for a simple Label with a Text property
that doesn't change, for example), I find this very frustrating. VB.NET does
not display this error, so why is C# displaying it? Thanks.

Hi,

It might be needed for the designer to work.
Just create an ID and move forward
 
S

Stan

When using C# for a codebehind language, Design View displays the error
message "Error Creating Control - ctrl type ID property is not specified"
and does not allow you to select the control in Design View. Since it is not
required that an ID is specified (I know that it is needed in order to do
many things, but it is not required for a simple Label with a Text property
that doesn't change, for example), I find this very frustrating. VB.NET does
not display this error, so why is C# displaying it? Thanks.

Since you don't want the ID property it must be the case that none of
the Label properties change. In which case why use one at all?

Web server controls are mean't to be used for dynamic content.
Anything that is static should be constructed from normal HTML. All
web server controls require extra processing so if they are not needed
they represent an unnecessary overhead.
 
N

Nathan Sokalski

The Label may have been a bad example. Here are some that may be more
appropriate:

RequiredFieldValidator (and many of the other validators): No extra code is
usually needed in the codebehind and the control is not referenced by any
other controls, so an ID is not necessary.

A Button inside a Repeater's ItemTemplate: When a Button is inside a
databound control's template, it is normally handled by the control's
ItemCommand event and uses the Button's CommandArgument property. The Button
itself, in many cases, is never referenced by it's ID.

I would also like to mention that some controls, such as the Image control,
even though they have HTML tags that do the exact same thing (in this case,
the img tag), they can still be easier. For example, when specifying the
location of the image file, you can use something such as
"~/images/myimagefile.gif" for the Image control's ImageUrl property no
matter what directory the *.aspx file is in, but the img tag's src attribute
requires either "/images/myimagefile.gif" or possibly some ../'s in the
path. Sometimes things like this can be make doing certain things more
convenient, especially when writing things like UserControls (*.ascx) that
may be used in several different directories. But regardless of whether it
is best programming practice or not, DesignView should still be able to show
the control.
 
S

Stan

The Label may have been a bad example. Here are some that may be more
appropriate:

RequiredFieldValidator (and many of the other validators): No extra code is
usually needed in the codebehind and the control is not referenced by any
other controls, so an ID is not necessary.

A Button inside a Repeater's ItemTemplate: When a Button is inside a
databound control's template, it is normally handled by the control's
ItemCommand event and uses the Button's CommandArgument property. The Button
itself, in many cases, is never referenced by it's ID.

I would also like to mention that some controls, such as the Image control,
even though they have HTML tags that do the exact same thing (in this case,
the img tag), they can still be easier. For example, when specifying the
location of the image file, you can use something such as
"~/images/myimagefile.gif" for the Image control's ImageUrl property no
matter what directory the *.aspx file is in, but the img tag's src attribute
requires either "/images/myimagefile.gif" or possibly some ../'s in the
path. Sometimes things like this can be make doing certain things more
convenient, especially when writing things like UserControls (*.ascx) that
may be used in several different directories. But regardless of whether it
is best programming practice or not, DesignView should still be able to show
the control.
--
Nathan Sokalski
(e-mail address removed)://www.nathansokalski.com/








- Show quoted text -

Nathan

I have tried creating a Label in page source without assigning an ID
in two separate dummy projects. One in VB the other in C#

In both cases they allowed me to switch to design view without error
and showed blank IDs in the properties window.

This is with VS 2008 Framework 3.5. If you are using an earlier
version then maybe MicroSoft has altered it so as to tolerate blank
IDs

On your point about using Image web server controls instead of html
controls inside web user controls, yes I totally agree (I've done that
too and for the same reason) but I don't regard that as a purely
static case. The HTML that is ultimately rendered for the src
attribute (derived from ImagUrl) will depend upon the location of the
host page so it's better to make it an active control.

I apologies if I underestimated your awareness of the issue but I
thought it worth mentioning given the context of your original post.

Stan
 
N

Nathan Sokalski

No offense taken, I don't always explain myself clearly, so I understand
when I am misunderstood. Anyway, what you said about you using VS 2008 and
..NET 3.5 may be the reason, since i am using VS 2005 and .NET 2.0.
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top