ASP.NET Namespace

What is the namespace that the Default.aspx page is on when I create an ASP.NET project?

And how to find the namespace of any other ASP.NET page in a project?

I am using VS2005. First I created an empty solution, and then added a website to it.

When I right-click and go to the "Add New Website" menu, I find the following ASP.NEt WebSites template (1st template), then I added it to my sln.

I am using C # and VS2005. In this case, it will not comply with VS2008.

+6
namespaces
source share
3 answers

Websites do not have / support a namespace. Web applications.

To answer the question, as a new β€œWebsite” is being created, the namespace is not included in the game. As for accessing other pages of WebForm pages from a Webform page, I see no reason for this. And I don’t think it’s skillful (correct me if I am wrong).

In any case, there are ways to get around. If you have several suitable business interfaces / UIs / other logics used in the class of one of the web forms, simply move these methods to say the XXX.cs file in App_Code. There is no need for a namespace, and you can use it in all classes of web forms.

+9
source share

Look at the code (default .aspx.cs in your case) on the page in question. There you will see your namespace. Aspx is a complement to the class in code, which is combined using a partial class declaration.

I just created a new web application project. It looks like this:

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 namespace "WebApplication1". You see it, right?

ADDED: I again created a website project to test this. Well, I confirm, I don't see any namespace declarations there. After a little search, I found this post:

asp.net - website and web application (link fixed)

The new compilation model threw out the visual studio project project itself, returned asp.net to the concept of "compilation on the fly," but eliminated the use of namespaces on the website and radically changed the way the user interface template and associated code were created.

In appearance, it just throws all the classes together, both page classes and your custom logical classes, which you usually put in the App_Code folder. The viewer class also does not show page objects, even if I transfer them to my own namespaces, but it does it right along with the namespaces for declarations in the App_Code folder. I suppose the guys from the VS team didn't want you to deal with namespaces for page classes.

+2
source share

Try to define the interface in the application code directory, and your code behind the file to implement the interface.

+2
source share

All Articles