views:

1258

answers:

2

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.

+1  A: 

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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

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

The new compilation model threw out the visual studio project file itself, took asp.net back to the "compile-on-the-fly" concept, all but eliminated the use of namespaces within a web site, and radically altered the way UI template and the associated code-behind were arranged.

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 the App_Code folder. I suppose the guys in VS team didn't mean you to care about namespaces for page classes.

Developer Art
Which planet do you live in? There are no namespace declarations in any asp.net code-behind file.
Are you kidding? Give me a minute, I'll get you an example.
Developer Art
I am using VS2005 and I never saw this happening in my Web projects.
I did this example in VS2008 Pro and I believe I saw more or less the same thing when I was using VS 2005. Maybe you were creating web site projects as opposed to web application projects? There the organization is somewhat different.
Developer Art
Now you have come to the point.....
A: 

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.

o.k.w
I need to inherit .aspx pages.
You mean u have a basepage.aspx with a codebind class "basepage". And you have a newpage.aspx which has a "newpage" class inherting "basepage"?If that is so, read this:http://www.west-wind.com/WebLog/posts/3016.aspx under the section "What to watch out for". Hope this helps.
o.k.w