Initial class name for Default page is _Default instead of Default

Discussion in 'ASP .Net' started by Sean Dockery, Jun 20, 2009.

  1. Sean Dockery

    Sean Dockery Guest

    When I create a new Web Application project, Visual Studio creates a web
    application project with a Default page. The Default page is associated to a
    class named _Default. If I delete the Default page and create a new page
    named Default, the code behind class is named Default (instead of _Default).
    Why does Visual Studio both naming the class _Default in the first place?
    This is something that I have always been curious about.
    Sean Dockery, Jun 20, 2009
    #1
    1. Advertising

  2. Sean Dockery

    Stan Guest

    Re: Initial class name for Default page is _Default instead ofDefault

    On 20 June, 16:11, Sean Dockery
    <> wrote:
    > When I create a new Web Application project, Visual Studio creates a web
    > application project with a Default page.  The Default page is associated to a
    > class named _Default.  If I delete the Default page and create a new page
    > named Default, the code behind class is named Default (instead of _Default).  
    > Why does Visual Studio both naming the class _Default in the first place?  
    > This is something that I have always been curious about.


    The class names used in code files have to be unique across the whole
    application.
    If you create a subfolder and add a default page then the class name
    will be in the form:

    foldername_default

    For the application root is doesn't have to be _default but that might
    be an artifact of the site creation process which follows the above
    regime with a null in place of the folder name. It would appear from
    your observations that when a page is added manually it doesn't quite
    follow the same logic and omits the underscore for the application
    root (so long as the resultant name doesn't already exist in which
    case it adds a digit e.g. default2).

    It is probably just an accidental inconsistency in the VS logic.

    HTH
    Stan, Jun 20, 2009
    #2
    1. Advertising

  3. This is because Default is a keyword, so Visual Studio uses _Default instead
    (see the following in the documentation for an example of Default being a
    keyword).

    ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vbalr/html/45fce9b9-d212-4b2d-ab86-6e359b8b57af.htm
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Sean Dockery" <> wrote in message
    news:...
    > When I create a new Web Application project, Visual Studio creates a web
    > application project with a Default page. The Default page is associated
    > to a
    > class named _Default. If I delete the Default page and create a new page
    > named Default, the code behind class is named Default (instead of
    > _Default).
    > Why does Visual Studio both naming the class _Default in the first place?
    > This is something that I have always been curious about.
    Nathan Sokalski, Jun 21, 2009
    #3
  4. Sean Dockery

    Sean Dockery Guest

    Re: Initial class name for Default page is _Default instead of Def

    That makes sense, except that using Default as the class name seems to work
    just fine, at least for C#.

    Curiously, I just tried a few minutes ago to perform the same set of steps
    of deleting and creating a web form page named Default. In C#, the class was
    named Default, but in VB, the class was *still* named _Default. If I try to
    change the class name manually in the VB project to be Default, Visual Studio
    complains that a keyword cannot be used as an identifier.

    I would guess that Microsoft names the class _Default in C# to be consistent
    with the vanilla web application project that is generated for VB.

    Thanks, Nathan, for pointing out the "other" language angle. I am sure that
    I will find other strange things that are probably the way that they are to
    satisfy all .NET languages.

    "Nathan Sokalski" wrote:

    > This is because Default is a keyword, so Visual Studio uses _Default instead
    > (see the following in the documentation for an example of Default being a
    > keyword).
    >
    > ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vbalr/html/45fce9b9-d212-4b2d-ab86-6e359b8b57af.htm
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Sean Dockery" <> wrote in message
    > news:...
    > > When I create a new Web Application project, Visual Studio creates a web
    > > application project with a Default page. The Default page is associated
    > > to a
    > > class named _Default. If I delete the Default page and create a new page
    > > named Default, the code behind class is named Default (instead of
    > > _Default).
    > > Why does Visual Studio both naming the class _Default in the first place?
    > > This is something that I have always been curious about.

    >
    >
    >
    Sean Dockery, Jun 21, 2009
    #4
    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. M
    Replies:
    1
    Views:
    6,104
    marcioCoelho
    Jul 24, 2006
  2. David Johnson
    Replies:
    1
    Views:
    777
    Showjumper
    Feb 6, 2004
  3. =?Utf-8?B?VGRhclRkYXI=?=

    The type '_Default' is ambiguous

    =?Utf-8?B?VGRhclRkYXI=?=, Sep 10, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    11,470
    =?Utf-8?B?VGRhclRkYXI=?=
    Sep 16, 2005
  4. Wayne Brantley
    Replies:
    3
    Views:
    4,635
    Wayne Brantley
    Dec 21, 2005
  5. RKT
    Replies:
    2
    Views:
    519
    Teemu Keiski
    Jan 28, 2006
Loading...

Share This Page