Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. namespace in ASP.NET 2.0

namespace in ASP.NET 2.0

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Duong Tien Nam
    wrote on last edited by
    #1

    I noticed that there is no namespace in the code file when I created a new ASP.NET project in VS2005. Anyone know why Microsoft make this change, pls help me (I love links :D) Thx all!

    M M 2 Replies Last reply
    0
    • D Duong Tien Nam

      I noticed that there is no namespace in the code file when I created a new ASP.NET project in VS2005. Anyone know why Microsoft make this change, pls help me (I love links :D) Thx all!

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi there. If you mean that you don't see the using or imports statements for referencing namespaces, it may be that they are already established in the project properties as defaults for all forms to use.

      D 1 Reply Last reply
      0
      • M Mike Ellison

        Hi there. If you mean that you don't see the using or imports statements for referencing namespaces, it may be that they are already established in the project properties as defaults for all forms to use.

        D Offline
        D Offline
        Duong Tien Nam
        wrote on last edited by
        #3

        this is VS.NET 2003 code generation for a page: .... namespace WebApplication1 { class Class1 { ... } } and the VS2005 version ... partial class Class1 { ... } no namespace (WebApplication1), thats what i mean :D, thx for reply

        1 Reply Last reply
        0
        • D Duong Tien Nam

          I noticed that there is no namespace in the code file when I created a new ASP.NET project in VS2005. Anyone know why Microsoft make this change, pls help me (I love links :D) Thx all!

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi Nam, Because of the changes in the ASP.NET compiling model and also in the web page code behind model, so by design the class in code-behind is put in the default namespace. Remember that this is partial (incomplete) class, and at runtime the ASP.NET will associate another partial class (normally put in the default namespace ASP) with the partial class in code-bebind to create a complete class to represent the web page. However, you can put the partial class in code-behind if you want, but you need to remember to update the Inherits attribute of the Page directive accordingly. For more information, you should see the documetation on the ASP.NET compiling model and the web page model in MSDN.

          D 1 Reply Last reply
          0
          • M minhpc_bk

            Hi Nam, Because of the changes in the ASP.NET compiling model and also in the web page code behind model, so by design the class in code-behind is put in the default namespace. Remember that this is partial (incomplete) class, and at runtime the ASP.NET will associate another partial class (normally put in the default namespace ASP) with the partial class in code-bebind to create a complete class to represent the web page. However, you can put the partial class in code-behind if you want, but you need to remember to update the Inherits attribute of the Page directive accordingly. For more information, you should see the documetation on the ASP.NET compiling model and the web page model in MSDN.

            D Offline
            D Offline
            Duong Tien Nam
            wrote on last edited by
            #5

            How to include the generated partial class to the main code-behind class as you said? Is there and option in the IDE to do that? I dont think that abandoning the namespace in the code-behind file is a good idea :( . Could you give me the links to find out more? I cant find them clearly in MSDN. Thx for reply.

            M 1 Reply Last reply
            0
            • D Duong Tien Nam

              How to include the generated partial class to the main code-behind class as you said? Is there and option in the IDE to do that? I dont think that abandoning the namespace in the code-behind file is a good idea :( . Could you give me the links to find out more? I cant find them clearly in MSDN. Thx for reply.

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              Nam, You can put the partial class in code-behind in your custom namespace as you would with the ASP.NET 1.1:

              namespace MyNameSpace
              {
              public partial class Class1 : System.Web.UI.Page
              {
              ....
              }
              }

              And you will do this in the code editor, also remember to update the Inherits attribute accordingly:

              <%@ Page Language="C#" AutoEventWireup="true" CodeFile="..." Inherits="MyNameSpace.Class1" %>

              So basically, you would not need to worry about the code to declare all the server controls placed in the web page .aspx since they are placed in another dynamic partial class generated by the ASP.NET. The idea behind this is to seperate all automatically generated code in a partial class so that the code in your code-behind is really neat and clean, and you can freely access the controls in code-behind.

              Duong Tien Nam wrote:

              I dont think that abandoning the namespace in the code-behind file is a good idea

              Unfortunately, I haven't seen a way using the IDE to set the namespace for the partial class by default, that means you would need to use the code edtior. And I guess that you might find it difficult or strange to you, but in fact, there are some big changes in the ASP.NET compiling model over the ASP.NET 1.1. In old version of the ASP.NET, you basically have a single output assembly whose name is normally the namespace declared in code-behind. At runtime, this assembly is put in the bind folder, and with this model you will have some disadvantages like updating the assembly. However, you should be much more flexible with the new compiling model introduced in the ASP.NET 2.0. You can find more information from the links: ASP.NET Compilation Overview [^] ASP.NET Web Page Code Model [^] http://weblogs.asp.net/scottgu/archive/2005/08/21/423201.aspx[^] You can certainly find more re

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups