Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Initial class name for Default page is _Default instead of Default

Reply
Thread Tools

Initial class name for Default page is _Default instead of Default

 
 
Sean Dockery
Guest
Posts: n/a
 
      06-20-2009
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.
 
Reply With Quote
 
 
 
 
Stan
Guest
Posts: n/a
 
      06-20-2009
On 20 June, 16:11, Sean Dockery
<(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      06-21-2009
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.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/

"Sean Dockery" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Sean Dockery
Guest
Posts: n/a
 
      06-21-2009
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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>
> "Sean Dockery" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
could not load type "_default" M ASP .Net 1 07-24-2006 04:29 PM
Accessing _Default page from a child derived from UserControl (Express 2005) RKT ASP .Net 2 01-28-2006 07:32 PM
The type '_Default' conflicts with the imported type '_Default' Wayne Brantley ASP .Net 3 12-21-2005 12:41 AM
The type '_Default' is ambiguous =?Utf-8?B?VGRhclRkYXI=?= ASP .Net 4 09-16-2005 05:23 PM
Parser Error Message: Could not load type 'winadmin._default' David Johnson ASP .Net 1 02-06-2004 05:35 PM



Advertisments