What is the namespace the Default.aspx page resides in when I create an ASP.NET project?
And how to find the namespace of any other ASP.NET page in the project?
I am using VS2005. I first created a blank solution and then added a webSite to it.
When I click right-button and go to 'Add New Web Site' - menu I find the following template ASP.NEt WebSites(1st template), then I added this to my sln.
I am using C# and VS2005. This will not match VS2008 in this case.
Look at the code-behind (Default.aspx.cs in your case) of a page in question. There you will see your namespace. Aspx is an addition to the class in code-behind that is merged using the partial class declaration.
I just created a new web application project. This what the code-behind looks like:
So you see the "WebApplication1" namespace. You see it, right?
ADDED: So I created a web site project again to check that out. Okay, I confirm, I do not see any namespace declarations there. After googling a little bit I found this post:
asp.net - Web Site vs. Web Application (link fixed)
From the looks of it, it just throws all classes together, both page classes and your custom logic classes you usually put into
App_Code
folder. Class viewer also does not show page objects even if I wrap them in my custom namespaces, but it does so correctly along with the namespaces for declarations in theApp_Code
folder. I suppose the guys in VS team didn't mean you to care about namespaces for page classes.Try defining an interface in the app code directory and have your code behind file implement the interface.
Web Sites do not have/support namespace. Web Applications do.
To answer the question, since a new 'Web Site' is created, namespace doesn't come into play. As to how to access other WebForm page classes from a Webform page, I haven't figure a reason for that. And I do not think it is do-able (correct me if I'm wrong).
Anyway there are ways to get around. If you have some reuable business/UI/other logics used within a class of one the webforms, simply move those methods out to say XXX.cs file under App_Code. There is no need for namespace and you can use it within all the webform classes.