C# says Error Creating Control when no ID is specified

Discussion in 'ASP .Net' started by Nathan Sokalski, Aug 4, 2008.

  1. 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.
     
    Nathan Sokalski, Aug 4, 2008
    #1
    1. Advertising

  2. On Aug 4, 8:06 am, "Nathan Sokalski" <>
    wrote:
    > 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
     
    Ignacio Machin ( .NET/ C# MVP ), Aug 4, 2008
    #2
    1. Advertising

  3. Nathan Sokalski

    Stan Guest

    On 4 Aug, 13:06, "Nathan Sokalski" <>
    wrote:
    > 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.
     
    Stan, Aug 6, 2008
    #3
  4. 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

    http://www.nathansokalski.com/

    "Stan" <> wrote in message
    news:...
    > On 4 Aug, 13:06, "Nathan Sokalski" <>
    > wrote:
    >> 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.
     
    Nathan Sokalski, Aug 6, 2008
    #4
  5. Nathan Sokalski

    Stan Guest

    On 6 Aug, 02:03, "Nathan Sokalski" <> wrote:
    > 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
    > ://www.nathansokalski.com/
    >
    > "Stan" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > On 4 Aug, 13:06, "Nathan Sokalski" <>
    > > wrote:
    > >> 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.- Hide quoted text -

    >
    > - 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
     
    Stan, Aug 7, 2008
    #5
  6. 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.

    "Stan" <> wrote in message
    news:...
    > On 6 Aug, 02:03, "Nathan Sokalski" <> wrote:
    >> 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
    >> ://www.nathansokalski.com/
    >>
    >> "Stan" <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > On 4 Aug, 13:06, "Nathan Sokalski" <>
    >> > wrote:
    >> >> 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.- Hide quoted text -

    >>
    >> - 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
     
    Nathan Sokalski, Aug 7, 2008
    #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. Ravi Ambros Wallau
    Replies:
    0
    Views:
    4,121
    Ravi Ambros Wallau
    Jun 1, 2005
  2. hfk0
    Replies:
    2
    Views:
    21,751
  3. Allan Ebdrup
    Replies:
    5
    Views:
    6,255
    crashkiwi
    Jun 30, 2009
  4. Ravi Ambros Wallau
    Replies:
    0
    Views:
    334
    Ravi Ambros Wallau
    Jun 1, 2005
  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:
    228
    Nathan Sokalski
    Aug 7, 2008
Loading...

Share This Page