Namespaces - broad question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Random

    Namespaces - broad question

    I'm confused about the proper use and usefulness of namespaces. I beleive I
    understand the purpose is so the developer can put classes within namespaces
    to essentially organize your code. And I understand that you declare your
    intention to use a namespace within a page through the "Inherits" attribute.
    I know that using "Inherits" isn't absolutely necessary, it's just
    recommended so the developer doesn't have to type out the entire namespace
    in code. I know that namespaces have to appear in the project assembly,
    however...

    How does the assembly find a namespace that the developer has written????
    In all the examples I've seen, namespaces have been written in codebehind
    pages. How does this make them accessible to the entire project? What's to
    prevent a duplicate namespace from being written in a different codebehind
    page? Is there a better place to write all the project namespaces for more
    centralized accessibility?

    And finally, how do namespaces DIFFER from classes?

    Random


  • Marina

    #2
    Re: Namespaces - broad question

    First of all, namespaces can be used with the 'Imports' keyword, so as not
    have to write out the full namespace for every class, not the 'Inherits'
    attribute.

    Think of namespaces as folders in your file system, and classes as the files
    in them. So a namespace itself isn't anything but an organizational
    container for classes - just as a folder is just a container for files.
    Classes are the actual things that you instantiate, and call methods on.

    I didn't really understand your questions. I think they all stem from not
    understanding what a namespace actually is.

    "Random" <cipherlad@hotm ail.com> wrote in message
    news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I'm confused about the proper use and usefulness of namespaces. I beleive[/color]
    I[color=blue]
    > understand the purpose is so the developer can put classes within[/color]
    namespaces[color=blue]
    > to essentially organize your code. And I understand that you declare your
    > intention to use a namespace within a page through the "Inherits"[/color]
    attribute.[color=blue]
    > I know that using "Inherits" isn't absolutely necessary, it's just
    > recommended so the developer doesn't have to type out the entire namespace
    > in code. I know that namespaces have to appear in the project assembly,
    > however...
    >
    > How does the assembly find a namespace that the developer has written????
    > In all the examples I've seen, namespaces have been written in codebehind
    > pages. How does this make them accessible to the entire project? What's[/color]
    to[color=blue]
    > prevent a duplicate namespace from being written in a different codebehind
    > page? Is there a better place to write all the project namespaces for[/color]
    more[color=blue]
    > centralized accessibility?
    >
    > And finally, how do namespaces DIFFER from classes?
    >
    > Random
    >
    >[/color]


    Comment

    • Marina

      #3
      Re: Namespaces - broad question

      First of all, namespaces can be used with the 'Imports' keyword, so as not
      have to write out the full namespace for every class, not the 'Inherits'
      attribute.

      Think of namespaces as folders in your file system, and classes as the files
      in them. So a namespace itself isn't anything but an organizational
      container for classes - just as a folder is just a container for files.
      Classes are the actual things that you instantiate, and call methods on.

      I didn't really understand your questions. I think they all stem from not
      understanding what a namespace actually is.

      "Random" <cipherlad@hotm ail.com> wrote in message
      news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=blue]
      > I'm confused about the proper use and usefulness of namespaces. I beleive[/color]
      I[color=blue]
      > understand the purpose is so the developer can put classes within[/color]
      namespaces[color=blue]
      > to essentially organize your code. And I understand that you declare your
      > intention to use a namespace within a page through the "Inherits"[/color]
      attribute.[color=blue]
      > I know that using "Inherits" isn't absolutely necessary, it's just
      > recommended so the developer doesn't have to type out the entire namespace
      > in code. I know that namespaces have to appear in the project assembly,
      > however...
      >
      > How does the assembly find a namespace that the developer has written????
      > In all the examples I've seen, namespaces have been written in codebehind
      > pages. How does this make them accessible to the entire project? What's[/color]
      to[color=blue]
      > prevent a duplicate namespace from being written in a different codebehind
      > page? Is there a better place to write all the project namespaces for[/color]
      more[color=blue]
      > centralized accessibility?
      >
      > And finally, how do namespaces DIFFER from classes?
      >
      > Random
      >
      >[/color]


      Comment

      • Random

        #4
        Re: Namespaces - broad question

        Hmm. I'm trying to teach myself from examples and tutorials and books.
        Specifically in this case, I'm trying to learn from the MS PortalStarterKi t.
        Specifically, the default page in that example has as the first line in
        default.aspx:

        <%@ Page CodeBehind="Def ault.aspx.vb" language="vb" AutoEventWireup ="false"
        Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>

        The codebehind page has:

        Namespace ASPNET.StarterK it.Portal
        Public Class CDefault
        Inherits System.Web.UI.P age
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        <code here>
        End Sub
        End Class
        End Namespace

        I'm trying to find out how and why this works the way that it does. It's
        more complex than the examples given by tutorials and books.

        And again, I'm trying to figure out how the namespace declared here makes
        it's way into the assembly. And because it does, somehow, does that make it
        available through the entire project?

        Random

        "Marina" <someone@nospam .com> wrote in message
        news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > First of all, namespaces can be used with the 'Imports' keyword, so as not
        > have to write out the full namespace for every class, not the 'Inherits'
        > attribute.
        >
        > Think of namespaces as folders in your file system, and classes as the[/color]
        files[color=blue]
        > in them. So a namespace itself isn't anything but an organizational
        > container for classes - just as a folder is just a container for files.
        > Classes are the actual things that you instantiate, and call methods on.
        >
        > I didn't really understand your questions. I think they all stem from not
        > understanding what a namespace actually is.
        >
        > "Random" <cipherlad@hotm ail.com> wrote in message
        > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=green]
        > > I'm confused about the proper use and usefulness of namespaces. I[/color][/color]
        beleive[color=blue]
        > I[color=green]
        > > understand the purpose is so the developer can put classes within[/color]
        > namespaces[color=green]
        > > to essentially organize your code. And I understand that you declare[/color][/color]
        your[color=blue][color=green]
        > > intention to use a namespace within a page through the "Inherits"[/color]
        > attribute.[color=green]
        > > I know that using "Inherits" isn't absolutely necessary, it's just
        > > recommended so the developer doesn't have to type out the entire[/color][/color]
        namespace[color=blue][color=green]
        > > in code. I know that namespaces have to appear in the project assembly,
        > > however...
        > >
        > > How does the assembly find a namespace that the developer has[/color][/color]
        written????[color=blue][color=green]
        > > In all the examples I've seen, namespaces have been written in[/color][/color]
        codebehind[color=blue][color=green]
        > > pages. How does this make them accessible to the entire project?[/color][/color]
        What's[color=blue]
        > to[color=green]
        > > prevent a duplicate namespace from being written in a different[/color][/color]
        codebehind[color=blue][color=green]
        > > page? Is there a better place to write all the project namespaces for[/color]
        > more[color=green]
        > > centralized accessibility?
        > >
        > > And finally, how do namespaces DIFFER from classes?
        > >
        > > Random
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Random

          #5
          Re: Namespaces - broad question

          Hmm. I'm trying to teach myself from examples and tutorials and books.
          Specifically in this case, I'm trying to learn from the MS PortalStarterKi t.
          Specifically, the default page in that example has as the first line in
          default.aspx:

          <%@ Page CodeBehind="Def ault.aspx.vb" language="vb" AutoEventWireup ="false"
          Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>

          The codebehind page has:

          Namespace ASPNET.StarterK it.Portal
          Public Class CDefault
          Inherits System.Web.UI.P age
          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
          System.EventArg s) Handles MyBase.Load
          <code here>
          End Sub
          End Class
          End Namespace

          I'm trying to find out how and why this works the way that it does. It's
          more complex than the examples given by tutorials and books.

          And again, I'm trying to figure out how the namespace declared here makes
          it's way into the assembly. And because it does, somehow, does that make it
          available through the entire project?

          Random

          "Marina" <someone@nospam .com> wrote in message
          news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          > First of all, namespaces can be used with the 'Imports' keyword, so as not
          > have to write out the full namespace for every class, not the 'Inherits'
          > attribute.
          >
          > Think of namespaces as folders in your file system, and classes as the[/color]
          files[color=blue]
          > in them. So a namespace itself isn't anything but an organizational
          > container for classes - just as a folder is just a container for files.
          > Classes are the actual things that you instantiate, and call methods on.
          >
          > I didn't really understand your questions. I think they all stem from not
          > understanding what a namespace actually is.
          >
          > "Random" <cipherlad@hotm ail.com> wrote in message
          > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=green]
          > > I'm confused about the proper use and usefulness of namespaces. I[/color][/color]
          beleive[color=blue]
          > I[color=green]
          > > understand the purpose is so the developer can put classes within[/color]
          > namespaces[color=green]
          > > to essentially organize your code. And I understand that you declare[/color][/color]
          your[color=blue][color=green]
          > > intention to use a namespace within a page through the "Inherits"[/color]
          > attribute.[color=green]
          > > I know that using "Inherits" isn't absolutely necessary, it's just
          > > recommended so the developer doesn't have to type out the entire[/color][/color]
          namespace[color=blue][color=green]
          > > in code. I know that namespaces have to appear in the project assembly,
          > > however...
          > >
          > > How does the assembly find a namespace that the developer has[/color][/color]
          written????[color=blue][color=green]
          > > In all the examples I've seen, namespaces have been written in[/color][/color]
          codebehind[color=blue][color=green]
          > > pages. How does this make them accessible to the entire project?[/color][/color]
          What's[color=blue]
          > to[color=green]
          > > prevent a duplicate namespace from being written in a different[/color][/color]
          codebehind[color=blue][color=green]
          > > page? Is there a better place to write all the project namespaces for[/color]
          > more[color=green]
          > > centralized accessibility?
          > >
          > > And finally, how do namespaces DIFFER from classes?
          > >
          > > Random
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Marina

            #6
            Re: Namespaces - broad question

            This inherits attribute, refers to the name of the class this page inherits
            from. The class's name is CDefault, but it is located in the
            ASPNET.StarterK it.Portal namespace, and so the namespace has to preceed it.

            At runtime, asp.net looks for a class with the name in the inherits
            attribute.

            This has nothing to do with projects, or namespaces being available. It is
            just the fully qualified name of the class.

            "Random" <cipherlad@hotm ail.com> wrote in message
            news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...[color=blue]
            > Hmm. I'm trying to teach myself from examples and tutorials and books.
            > Specifically in this case, I'm trying to learn from the MS[/color]
            PortalStarterKi t.[color=blue]
            > Specifically, the default page in that example has as the first line in
            > default.aspx:
            >
            > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"[/color]
            AutoEventWireup ="false"[color=blue]
            > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
            >
            > The codebehind page has:
            >
            > Namespace ASPNET.StarterK it.Portal
            > Public Class CDefault
            > Inherits System.Web.UI.P age
            > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
            > System.EventArg s) Handles MyBase.Load
            > <code here>
            > End Sub
            > End Class
            > End Namespace
            >
            > I'm trying to find out how and why this works the way that it does. It's
            > more complex than the examples given by tutorials and books.
            >
            > And again, I'm trying to figure out how the namespace declared here makes
            > it's way into the assembly. And because it does, somehow, does that make[/color]
            it[color=blue]
            > available through the entire project?
            >
            > Random
            >
            > "Marina" <someone@nospam .com> wrote in message
            > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..[color=green]
            > > First of all, namespaces can be used with the 'Imports' keyword, so as[/color][/color]
            not[color=blue][color=green]
            > > have to write out the full namespace for every class, not the 'Inherits'
            > > attribute.
            > >
            > > Think of namespaces as folders in your file system, and classes as the[/color]
            > files[color=green]
            > > in them. So a namespace itself isn't anything but an organizational
            > > container for classes - just as a folder is just a container for files.
            > > Classes are the actual things that you instantiate, and call methods on.
            > >
            > > I didn't really understand your questions. I think they all stem from[/color][/color]
            not[color=blue][color=green]
            > > understanding what a namespace actually is.
            > >
            > > "Random" <cipherlad@hotm ail.com> wrote in message
            > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=darkred]
            > > > I'm confused about the proper use and usefulness of namespaces. I[/color][/color]
            > beleive[color=green]
            > > I[color=darkred]
            > > > understand the purpose is so the developer can put classes within[/color]
            > > namespaces[color=darkred]
            > > > to essentially organize your code. And I understand that you declare[/color][/color]
            > your[color=green][color=darkred]
            > > > intention to use a namespace within a page through the "Inherits"[/color]
            > > attribute.[color=darkred]
            > > > I know that using "Inherits" isn't absolutely necessary, it's just
            > > > recommended so the developer doesn't have to type out the entire[/color][/color]
            > namespace[color=green][color=darkred]
            > > > in code. I know that namespaces have to appear in the project[/color][/color][/color]
            assembly,[color=blue][color=green][color=darkred]
            > > > however...
            > > >
            > > > How does the assembly find a namespace that the developer has[/color][/color]
            > written????[color=green][color=darkred]
            > > > In all the examples I've seen, namespaces have been written in[/color][/color]
            > codebehind[color=green][color=darkred]
            > > > pages. How does this make them accessible to the entire project?[/color][/color]
            > What's[color=green]
            > > to[color=darkred]
            > > > prevent a duplicate namespace from being written in a different[/color][/color]
            > codebehind[color=green][color=darkred]
            > > > page? Is there a better place to write all the project namespaces for[/color]
            > > more[color=darkred]
            > > > centralized accessibility?
            > > >
            > > > And finally, how do namespaces DIFFER from classes?
            > > >
            > > > Random
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Marina

              #7
              Re: Namespaces - broad question

              This inherits attribute, refers to the name of the class this page inherits
              from. The class's name is CDefault, but it is located in the
              ASPNET.StarterK it.Portal namespace, and so the namespace has to preceed it.

              At runtime, asp.net looks for a class with the name in the inherits
              attribute.

              This has nothing to do with projects, or namespaces being available. It is
              just the fully qualified name of the class.

              "Random" <cipherlad@hotm ail.com> wrote in message
              news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...[color=blue]
              > Hmm. I'm trying to teach myself from examples and tutorials and books.
              > Specifically in this case, I'm trying to learn from the MS[/color]
              PortalStarterKi t.[color=blue]
              > Specifically, the default page in that example has as the first line in
              > default.aspx:
              >
              > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"[/color]
              AutoEventWireup ="false"[color=blue]
              > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
              >
              > The codebehind page has:
              >
              > Namespace ASPNET.StarterK it.Portal
              > Public Class CDefault
              > Inherits System.Web.UI.P age
              > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
              > System.EventArg s) Handles MyBase.Load
              > <code here>
              > End Sub
              > End Class
              > End Namespace
              >
              > I'm trying to find out how and why this works the way that it does. It's
              > more complex than the examples given by tutorials and books.
              >
              > And again, I'm trying to figure out how the namespace declared here makes
              > it's way into the assembly. And because it does, somehow, does that make[/color]
              it[color=blue]
              > available through the entire project?
              >
              > Random
              >
              > "Marina" <someone@nospam .com> wrote in message
              > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..[color=green]
              > > First of all, namespaces can be used with the 'Imports' keyword, so as[/color][/color]
              not[color=blue][color=green]
              > > have to write out the full namespace for every class, not the 'Inherits'
              > > attribute.
              > >
              > > Think of namespaces as folders in your file system, and classes as the[/color]
              > files[color=green]
              > > in them. So a namespace itself isn't anything but an organizational
              > > container for classes - just as a folder is just a container for files.
              > > Classes are the actual things that you instantiate, and call methods on.
              > >
              > > I didn't really understand your questions. I think they all stem from[/color][/color]
              not[color=blue][color=green]
              > > understanding what a namespace actually is.
              > >
              > > "Random" <cipherlad@hotm ail.com> wrote in message
              > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=darkred]
              > > > I'm confused about the proper use and usefulness of namespaces. I[/color][/color]
              > beleive[color=green]
              > > I[color=darkred]
              > > > understand the purpose is so the developer can put classes within[/color]
              > > namespaces[color=darkred]
              > > > to essentially organize your code. And I understand that you declare[/color][/color]
              > your[color=green][color=darkred]
              > > > intention to use a namespace within a page through the "Inherits"[/color]
              > > attribute.[color=darkred]
              > > > I know that using "Inherits" isn't absolutely necessary, it's just
              > > > recommended so the developer doesn't have to type out the entire[/color][/color]
              > namespace[color=green][color=darkred]
              > > > in code. I know that namespaces have to appear in the project[/color][/color][/color]
              assembly,[color=blue][color=green][color=darkred]
              > > > however...
              > > >
              > > > How does the assembly find a namespace that the developer has[/color][/color]
              > written????[color=green][color=darkred]
              > > > In all the examples I've seen, namespaces have been written in[/color][/color]
              > codebehind[color=green][color=darkred]
              > > > pages. How does this make them accessible to the entire project?[/color][/color]
              > What's[color=green]
              > > to[color=darkred]
              > > > prevent a duplicate namespace from being written in a different[/color][/color]
              > codebehind[color=green][color=darkred]
              > > > page? Is there a better place to write all the project namespaces for[/color]
              > > more[color=darkred]
              > > > centralized accessibility?
              > > >
              > > > And finally, how do namespaces DIFFER from classes?
              > > >
              > > > Random
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Random

                #8
                Re: Namespaces - broad question

                Okay, that clarifies the "Inherits" vs. "Imports" question very well.
                Thanks.

                As far as the namespace being available in the assembly, though, let me give
                you an example...

                Using the portal code I gave before, would I be able to write another aspx
                page, use the same "Inherits=<full y qualified class name>" phrasing, without
                that class being written into the different codebehind page referenced in
                the new aspx page?

                If yes, why? Shouldn't namespaces be written in a more centrally referenced
                file?

                If no, then how can the assembly keep track of all the declared namespaces?
                And what would it do if two or more codebehind references had the same
                namespace and class written in them?

                Random

                "Marina" <someone@nospam .com> wrote in message
                news:eqT6TmYHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=blue]
                > This inherits attribute, refers to the name of the class this page[/color]
                inherits[color=blue]
                > from. The class's name is CDefault, but it is located in the
                > ASPNET.StarterK it.Portal namespace, and so the namespace has to preceed[/color]
                it.[color=blue]
                >
                > At runtime, asp.net looks for a class with the name in the inherits
                > attribute.
                >
                > This has nothing to do with projects, or namespaces being available. It is
                > just the fully qualified name of the class.
                >
                > "Random" <cipherlad@hotm ail.com> wrote in message
                > news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...[color=green]
                > > Hmm. I'm trying to teach myself from examples and tutorials and books.
                > > Specifically in this case, I'm trying to learn from the MS[/color]
                > PortalStarterKi t.[color=green]
                > > Specifically, the default page in that example has as the first line in
                > > default.aspx:
                > >
                > > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"[/color]
                > AutoEventWireup ="false"[color=green]
                > > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
                > >
                > > The codebehind page has:
                > >
                > > Namespace ASPNET.StarterK it.Portal
                > > Public Class CDefault
                > > Inherits System.Web.UI.P age
                > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
                > > System.EventArg s) Handles MyBase.Load
                > > <code here>
                > > End Sub
                > > End Class
                > > End Namespace
                > >
                > > I'm trying to find out how and why this works the way that it does.[/color][/color]
                It's[color=blue][color=green]
                > > more complex than the examples given by tutorials and books.
                > >
                > > And again, I'm trying to figure out how the namespace declared here[/color][/color]
                makes[color=blue][color=green]
                > > it's way into the assembly. And because it does, somehow, does that[/color][/color]
                make[color=blue]
                > it[color=green]
                > > available through the entire project?
                > >
                > > Random
                > >
                > > "Marina" <someone@nospam .com> wrote in message
                > > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..[color=darkred]
                > > > First of all, namespaces can be used with the 'Imports' keyword, so as[/color][/color]
                > not[color=green][color=darkred]
                > > > have to write out the full namespace for every class, not the[/color][/color][/color]
                'Inherits'[color=blue][color=green][color=darkred]
                > > > attribute.
                > > >
                > > > Think of namespaces as folders in your file system, and classes as the[/color]
                > > files[color=darkred]
                > > > in them. So a namespace itself isn't anything but an organizational
                > > > container for classes - just as a folder is just a container for[/color][/color][/color]
                files.[color=blue][color=green][color=darkred]
                > > > Classes are the actual things that you instantiate, and call methods[/color][/color][/color]
                on.[color=blue][color=green][color=darkred]
                > > >
                > > > I didn't really understand your questions. I think they all stem from[/color][/color]
                > not[color=green][color=darkred]
                > > > understanding what a namespace actually is.
                > > >
                > > > "Random" <cipherlad@hotm ail.com> wrote in message
                > > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...
                > > > > I'm confused about the proper use and usefulness of namespaces. I[/color]
                > > beleive[color=darkred]
                > > > I
                > > > > understand the purpose is so the developer can put classes within
                > > > namespaces
                > > > > to essentially organize your code. And I understand that you[/color][/color][/color]
                declare[color=blue][color=green]
                > > your[color=darkred]
                > > > > intention to use a namespace within a page through the "Inherits"
                > > > attribute.
                > > > > I know that using "Inherits" isn't absolutely necessary, it's just
                > > > > recommended so the developer doesn't have to type out the entire[/color]
                > > namespace[color=darkred]
                > > > > in code. I know that namespaces have to appear in the project[/color][/color]
                > assembly,[color=green][color=darkred]
                > > > > however...
                > > > >
                > > > > How does the assembly find a namespace that the developer has[/color]
                > > written????[color=darkred]
                > > > > In all the examples I've seen, namespaces have been written in[/color]
                > > codebehind[color=darkred]
                > > > > pages. How does this make them accessible to the entire project?[/color]
                > > What's[color=darkred]
                > > > to
                > > > > prevent a duplicate namespace from being written in a different[/color]
                > > codebehind[color=darkred]
                > > > > page? Is there a better place to write all the project namespaces[/color][/color][/color]
                for[color=blue][color=green][color=darkred]
                > > > more
                > > > > centralized accessibility?
                > > > >
                > > > > And finally, how do namespaces DIFFER from classes?
                > > > >
                > > > > Random
                > > > >
                > > > >
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Random

                  #9
                  Re: Namespaces - broad question

                  Okay, that clarifies the "Inherits" vs. "Imports" question very well.
                  Thanks.

                  As far as the namespace being available in the assembly, though, let me give
                  you an example...

                  Using the portal code I gave before, would I be able to write another aspx
                  page, use the same "Inherits=<full y qualified class name>" phrasing, without
                  that class being written into the different codebehind page referenced in
                  the new aspx page?

                  If yes, why? Shouldn't namespaces be written in a more centrally referenced
                  file?

                  If no, then how can the assembly keep track of all the declared namespaces?
                  And what would it do if two or more codebehind references had the same
                  namespace and class written in them?

                  Random

                  "Marina" <someone@nospam .com> wrote in message
                  news:eqT6TmYHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=blue]
                  > This inherits attribute, refers to the name of the class this page[/color]
                  inherits[color=blue]
                  > from. The class's name is CDefault, but it is located in the
                  > ASPNET.StarterK it.Portal namespace, and so the namespace has to preceed[/color]
                  it.[color=blue]
                  >
                  > At runtime, asp.net looks for a class with the name in the inherits
                  > attribute.
                  >
                  > This has nothing to do with projects, or namespaces being available. It is
                  > just the fully qualified name of the class.
                  >
                  > "Random" <cipherlad@hotm ail.com> wrote in message
                  > news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...[color=green]
                  > > Hmm. I'm trying to teach myself from examples and tutorials and books.
                  > > Specifically in this case, I'm trying to learn from the MS[/color]
                  > PortalStarterKi t.[color=green]
                  > > Specifically, the default page in that example has as the first line in
                  > > default.aspx:
                  > >
                  > > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"[/color]
                  > AutoEventWireup ="false"[color=green]
                  > > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
                  > >
                  > > The codebehind page has:
                  > >
                  > > Namespace ASPNET.StarterK it.Portal
                  > > Public Class CDefault
                  > > Inherits System.Web.UI.P age
                  > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
                  > > System.EventArg s) Handles MyBase.Load
                  > > <code here>
                  > > End Sub
                  > > End Class
                  > > End Namespace
                  > >
                  > > I'm trying to find out how and why this works the way that it does.[/color][/color]
                  It's[color=blue][color=green]
                  > > more complex than the examples given by tutorials and books.
                  > >
                  > > And again, I'm trying to figure out how the namespace declared here[/color][/color]
                  makes[color=blue][color=green]
                  > > it's way into the assembly. And because it does, somehow, does that[/color][/color]
                  make[color=blue]
                  > it[color=green]
                  > > available through the entire project?
                  > >
                  > > Random
                  > >
                  > > "Marina" <someone@nospam .com> wrote in message
                  > > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..[color=darkred]
                  > > > First of all, namespaces can be used with the 'Imports' keyword, so as[/color][/color]
                  > not[color=green][color=darkred]
                  > > > have to write out the full namespace for every class, not the[/color][/color][/color]
                  'Inherits'[color=blue][color=green][color=darkred]
                  > > > attribute.
                  > > >
                  > > > Think of namespaces as folders in your file system, and classes as the[/color]
                  > > files[color=darkred]
                  > > > in them. So a namespace itself isn't anything but an organizational
                  > > > container for classes - just as a folder is just a container for[/color][/color][/color]
                  files.[color=blue][color=green][color=darkred]
                  > > > Classes are the actual things that you instantiate, and call methods[/color][/color][/color]
                  on.[color=blue][color=green][color=darkred]
                  > > >
                  > > > I didn't really understand your questions. I think they all stem from[/color][/color]
                  > not[color=green][color=darkred]
                  > > > understanding what a namespace actually is.
                  > > >
                  > > > "Random" <cipherlad@hotm ail.com> wrote in message
                  > > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...
                  > > > > I'm confused about the proper use and usefulness of namespaces. I[/color]
                  > > beleive[color=darkred]
                  > > > I
                  > > > > understand the purpose is so the developer can put classes within
                  > > > namespaces
                  > > > > to essentially organize your code. And I understand that you[/color][/color][/color]
                  declare[color=blue][color=green]
                  > > your[color=darkred]
                  > > > > intention to use a namespace within a page through the "Inherits"
                  > > > attribute.
                  > > > > I know that using "Inherits" isn't absolutely necessary, it's just
                  > > > > recommended so the developer doesn't have to type out the entire[/color]
                  > > namespace[color=darkred]
                  > > > > in code. I know that namespaces have to appear in the project[/color][/color]
                  > assembly,[color=green][color=darkred]
                  > > > > however...
                  > > > >
                  > > > > How does the assembly find a namespace that the developer has[/color]
                  > > written????[color=darkred]
                  > > > > In all the examples I've seen, namespaces have been written in[/color]
                  > > codebehind[color=darkred]
                  > > > > pages. How does this make them accessible to the entire project?[/color]
                  > > What's[color=darkred]
                  > > > to
                  > > > > prevent a duplicate namespace from being written in a different[/color]
                  > > codebehind[color=darkred]
                  > > > > page? Is there a better place to write all the project namespaces[/color][/color][/color]
                  for[color=blue][color=green][color=darkred]
                  > > > more
                  > > > > centralized accessibility?
                  > > > >
                  > > > > And finally, how do namespaces DIFFER from classes?
                  > > > >
                  > > > > Random
                  > > > >
                  > > > >
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Marina

                    #10
                    Re: Namespaces - broad question

                    I have no idea what you are talking about to be honest.

                    The class is already in a namespace - the Inherits attribute is just
                    referencing. It isn't creating a new namespace or a new class. So I have no
                    idea what you are talking about when you ask about namespaces being written
                    in central locations.

                    You can have any number of pages inherit from the same class - as long as
                    that class actually exists. In the visual studio model, you would have to
                    manually do that, because it assume a 1 to 1 ration between pages and code
                    behind classes.

                    If you tried to compiled two classes with the same name into the same
                    assembly, the compiler would not allow you to do this. The assembly itself
                    knows what classes it has, and what namespace each one is in, in it's
                    manifest.

                    I would recommend you start at the very basics of ASP.NET, it sounds like
                    you are missing some basic concept about how this all works. In your first
                    post you asked about the difference between a namespace and a class - so it
                    seems like you need to go to the beginning of .NET, and not just into the
                    middle of ASP.NET.

                    "Random" <cipherlad@hotm ail.com> wrote in message
                    news:uau2myYHEH A.3032@TK2MSFTN GP09.phx.gbl...[color=blue]
                    > Okay, that clarifies the "Inherits" vs. "Imports" question very well.
                    > Thanks.
                    >
                    > As far as the namespace being available in the assembly, though, let me[/color]
                    give[color=blue]
                    > you an example...
                    >
                    > Using the portal code I gave before, would I be able to write another aspx
                    > page, use the same "Inherits=<full y qualified class name>" phrasing,[/color]
                    without[color=blue]
                    > that class being written into the different codebehind page referenced in
                    > the new aspx page?
                    >
                    > If yes, why? Shouldn't namespaces be written in a more centrally[/color]
                    referenced[color=blue]
                    > file?
                    >
                    > If no, then how can the assembly keep track of all the declared[/color]
                    namespaces?[color=blue]
                    > And what would it do if two or more codebehind references had the same
                    > namespace and class written in them?
                    >
                    > Random
                    >
                    > "Marina" <someone@nospam .com> wrote in message
                    > news:eqT6TmYHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=green]
                    > > This inherits attribute, refers to the name of the class this page[/color]
                    > inherits[color=green]
                    > > from. The class's name is CDefault, but it is located in the
                    > > ASPNET.StarterK it.Portal namespace, and so the namespace has to preceed[/color]
                    > it.[color=green]
                    > >
                    > > At runtime, asp.net looks for a class with the name in the inherits
                    > > attribute.
                    > >
                    > > This has nothing to do with projects, or namespaces being available. It[/color][/color]
                    is[color=blue][color=green]
                    > > just the fully qualified name of the class.
                    > >
                    > > "Random" <cipherlad@hotm ail.com> wrote in message
                    > > news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...[color=darkred]
                    > > > Hmm. I'm trying to teach myself from examples and tutorials and[/color][/color][/color]
                    books.[color=blue][color=green][color=darkred]
                    > > > Specifically in this case, I'm trying to learn from the MS[/color]
                    > > PortalStarterKi t.[color=darkred]
                    > > > Specifically, the default page in that example has as the first line[/color][/color][/color]
                    in[color=blue][color=green][color=darkred]
                    > > > default.aspx:
                    > > >
                    > > > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"[/color]
                    > > AutoEventWireup ="false"[color=darkred]
                    > > > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
                    > > >
                    > > > The codebehind page has:
                    > > >
                    > > > Namespace ASPNET.StarterK it.Portal
                    > > > Public Class CDefault
                    > > > Inherits System.Web.UI.P age
                    > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e[/color][/color][/color]
                    As[color=blue][color=green][color=darkred]
                    > > > System.EventArg s) Handles MyBase.Load
                    > > > <code here>
                    > > > End Sub
                    > > > End Class
                    > > > End Namespace
                    > > >
                    > > > I'm trying to find out how and why this works the way that it does.[/color][/color]
                    > It's[color=green][color=darkred]
                    > > > more complex than the examples given by tutorials and books.
                    > > >
                    > > > And again, I'm trying to figure out how the namespace declared here[/color][/color]
                    > makes[color=green][color=darkred]
                    > > > it's way into the assembly. And because it does, somehow, does that[/color][/color]
                    > make[color=green]
                    > > it[color=darkred]
                    > > > available through the entire project?
                    > > >
                    > > > Random
                    > > >
                    > > > "Marina" <someone@nospam .com> wrote in message
                    > > > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..
                    > > > > First of all, namespaces can be used with the 'Imports' keyword, so[/color][/color][/color]
                    as[color=blue][color=green]
                    > > not[color=darkred]
                    > > > > have to write out the full namespace for every class, not the[/color][/color]
                    > 'Inherits'[color=green][color=darkred]
                    > > > > attribute.
                    > > > >
                    > > > > Think of namespaces as folders in your file system, and classes as[/color][/color][/color]
                    the[color=blue][color=green][color=darkred]
                    > > > files
                    > > > > in them. So a namespace itself isn't anything but an organizational
                    > > > > container for classes - just as a folder is just a container for[/color][/color]
                    > files.[color=green][color=darkred]
                    > > > > Classes are the actual things that you instantiate, and call methods[/color][/color]
                    > on.[color=green][color=darkred]
                    > > > >
                    > > > > I didn't really understand your questions. I think they all stem[/color][/color][/color]
                    from[color=blue][color=green]
                    > > not[color=darkred]
                    > > > > understanding what a namespace actually is.
                    > > > >
                    > > > > "Random" <cipherlad@hotm ail.com> wrote in message
                    > > > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...
                    > > > > > I'm confused about the proper use and usefulness of namespaces. I
                    > > > beleive
                    > > > > I
                    > > > > > understand the purpose is so the developer can put classes within
                    > > > > namespaces
                    > > > > > to essentially organize your code. And I understand that you[/color][/color]
                    > declare[color=green][color=darkred]
                    > > > your
                    > > > > > intention to use a namespace within a page through the "Inherits"
                    > > > > attribute.
                    > > > > > I know that using "Inherits" isn't absolutely necessary, it's just
                    > > > > > recommended so the developer doesn't have to type out the entire
                    > > > namespace
                    > > > > > in code. I know that namespaces have to appear in the project[/color]
                    > > assembly,[color=darkred]
                    > > > > > however...
                    > > > > >
                    > > > > > How does the assembly find a namespace that the developer has
                    > > > written????
                    > > > > > In all the examples I've seen, namespaces have been written in
                    > > > codebehind
                    > > > > > pages. How does this make them accessible to the entire project?
                    > > > What's
                    > > > > to
                    > > > > > prevent a duplicate namespace from being written in a different
                    > > > codebehind
                    > > > > > page? Is there a better place to write all the project namespaces[/color][/color]
                    > for[color=green][color=darkred]
                    > > > > more
                    > > > > > centralized accessibility?
                    > > > > >
                    > > > > > And finally, how do namespaces DIFFER from classes?
                    > > > > >
                    > > > > > Random
                    > > > > >
                    > > > > >
                    > > > >
                    > > > >
                    > > >
                    > > >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Marina

                      #11
                      Re: Namespaces - broad question

                      I have no idea what you are talking about to be honest.

                      The class is already in a namespace - the Inherits attribute is just
                      referencing. It isn't creating a new namespace or a new class. So I have no
                      idea what you are talking about when you ask about namespaces being written
                      in central locations.

                      You can have any number of pages inherit from the same class - as long as
                      that class actually exists. In the visual studio model, you would have to
                      manually do that, because it assume a 1 to 1 ration between pages and code
                      behind classes.

                      If you tried to compiled two classes with the same name into the same
                      assembly, the compiler would not allow you to do this. The assembly itself
                      knows what classes it has, and what namespace each one is in, in it's
                      manifest.

                      I would recommend you start at the very basics of ASP.NET, it sounds like
                      you are missing some basic concept about how this all works. In your first
                      post you asked about the difference between a namespace and a class - so it
                      seems like you need to go to the beginning of .NET, and not just into the
                      middle of ASP.NET.

                      "Random" <cipherlad@hotm ail.com> wrote in message
                      news:uau2myYHEH A.3032@TK2MSFTN GP09.phx.gbl...[color=blue]
                      > Okay, that clarifies the "Inherits" vs. "Imports" question very well.
                      > Thanks.
                      >
                      > As far as the namespace being available in the assembly, though, let me[/color]
                      give[color=blue]
                      > you an example...
                      >
                      > Using the portal code I gave before, would I be able to write another aspx
                      > page, use the same "Inherits=<full y qualified class name>" phrasing,[/color]
                      without[color=blue]
                      > that class being written into the different codebehind page referenced in
                      > the new aspx page?
                      >
                      > If yes, why? Shouldn't namespaces be written in a more centrally[/color]
                      referenced[color=blue]
                      > file?
                      >
                      > If no, then how can the assembly keep track of all the declared[/color]
                      namespaces?[color=blue]
                      > And what would it do if two or more codebehind references had the same
                      > namespace and class written in them?
                      >
                      > Random
                      >
                      > "Marina" <someone@nospam .com> wrote in message
                      > news:eqT6TmYHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=green]
                      > > This inherits attribute, refers to the name of the class this page[/color]
                      > inherits[color=green]
                      > > from. The class's name is CDefault, but it is located in the
                      > > ASPNET.StarterK it.Portal namespace, and so the namespace has to preceed[/color]
                      > it.[color=green]
                      > >
                      > > At runtime, asp.net looks for a class with the name in the inherits
                      > > attribute.
                      > >
                      > > This has nothing to do with projects, or namespaces being available. It[/color][/color]
                      is[color=blue][color=green]
                      > > just the fully qualified name of the class.
                      > >
                      > > "Random" <cipherlad@hotm ail.com> wrote in message
                      > > news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...[color=darkred]
                      > > > Hmm. I'm trying to teach myself from examples and tutorials and[/color][/color][/color]
                      books.[color=blue][color=green][color=darkred]
                      > > > Specifically in this case, I'm trying to learn from the MS[/color]
                      > > PortalStarterKi t.[color=darkred]
                      > > > Specifically, the default page in that example has as the first line[/color][/color][/color]
                      in[color=blue][color=green][color=darkred]
                      > > > default.aspx:
                      > > >
                      > > > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"[/color]
                      > > AutoEventWireup ="false"[color=darkred]
                      > > > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
                      > > >
                      > > > The codebehind page has:
                      > > >
                      > > > Namespace ASPNET.StarterK it.Portal
                      > > > Public Class CDefault
                      > > > Inherits System.Web.UI.P age
                      > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e[/color][/color][/color]
                      As[color=blue][color=green][color=darkred]
                      > > > System.EventArg s) Handles MyBase.Load
                      > > > <code here>
                      > > > End Sub
                      > > > End Class
                      > > > End Namespace
                      > > >
                      > > > I'm trying to find out how and why this works the way that it does.[/color][/color]
                      > It's[color=green][color=darkred]
                      > > > more complex than the examples given by tutorials and books.
                      > > >
                      > > > And again, I'm trying to figure out how the namespace declared here[/color][/color]
                      > makes[color=green][color=darkred]
                      > > > it's way into the assembly. And because it does, somehow, does that[/color][/color]
                      > make[color=green]
                      > > it[color=darkred]
                      > > > available through the entire project?
                      > > >
                      > > > Random
                      > > >
                      > > > "Marina" <someone@nospam .com> wrote in message
                      > > > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..
                      > > > > First of all, namespaces can be used with the 'Imports' keyword, so[/color][/color][/color]
                      as[color=blue][color=green]
                      > > not[color=darkred]
                      > > > > have to write out the full namespace for every class, not the[/color][/color]
                      > 'Inherits'[color=green][color=darkred]
                      > > > > attribute.
                      > > > >
                      > > > > Think of namespaces as folders in your file system, and classes as[/color][/color][/color]
                      the[color=blue][color=green][color=darkred]
                      > > > files
                      > > > > in them. So a namespace itself isn't anything but an organizational
                      > > > > container for classes - just as a folder is just a container for[/color][/color]
                      > files.[color=green][color=darkred]
                      > > > > Classes are the actual things that you instantiate, and call methods[/color][/color]
                      > on.[color=green][color=darkred]
                      > > > >
                      > > > > I didn't really understand your questions. I think they all stem[/color][/color][/color]
                      from[color=blue][color=green]
                      > > not[color=darkred]
                      > > > > understanding what a namespace actually is.
                      > > > >
                      > > > > "Random" <cipherlad@hotm ail.com> wrote in message
                      > > > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...
                      > > > > > I'm confused about the proper use and usefulness of namespaces. I
                      > > > beleive
                      > > > > I
                      > > > > > understand the purpose is so the developer can put classes within
                      > > > > namespaces
                      > > > > > to essentially organize your code. And I understand that you[/color][/color]
                      > declare[color=green][color=darkred]
                      > > > your
                      > > > > > intention to use a namespace within a page through the "Inherits"
                      > > > > attribute.
                      > > > > > I know that using "Inherits" isn't absolutely necessary, it's just
                      > > > > > recommended so the developer doesn't have to type out the entire
                      > > > namespace
                      > > > > > in code. I know that namespaces have to appear in the project[/color]
                      > > assembly,[color=darkred]
                      > > > > > however...
                      > > > > >
                      > > > > > How does the assembly find a namespace that the developer has
                      > > > written????
                      > > > > > In all the examples I've seen, namespaces have been written in
                      > > > codebehind
                      > > > > > pages. How does this make them accessible to the entire project?
                      > > > What's
                      > > > > to
                      > > > > > prevent a duplicate namespace from being written in a different
                      > > > codebehind
                      > > > > > page? Is there a better place to write all the project namespaces[/color][/color]
                      > for[color=green][color=darkred]
                      > > > > more
                      > > > > > centralized accessibility?
                      > > > > >
                      > > > > > And finally, how do namespaces DIFFER from classes?
                      > > > > >
                      > > > > > Random
                      > > > > >
                      > > > > >
                      > > > >
                      > > > >
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • Random

                        #12
                        Re: Namespaces - broad question

                        I know you are not trying to offend, Marina, but I am an experienced
                        programmer, just new to .NET, and I have read a lot, from the basics. I am
                        disappointed that a lot of the 'beginner' material has been unhelpful when
                        it comes to an architectural overview of ASP.NET, which is what I am trying
                        to clarify here. I thought that by asking 'basic' questions, I might get a
                        better understanding of how things fit into the whole. So please be patient
                        with me in this.

                        I realize that while Visual Studio automatically encourages a 1 to 1
                        relationship between aspx and codebehind pages, this does not necessarily
                        need to be the case. I also realize that errors would occur during
                        compiling if the same class was written in different places. What I don't
                        understand is how Visual Studio keeps track in the assembly of where all
                        these written classes are?

                        As another example, what if I wrote an aspx page that inherited a class
                        contained in a codebehind page that was NOT referenced by the aspx page?
                        Since the class is found in the assembly, how would the aspx page know where
                        to look? When the code is all compiled, does it automatically all the
                        classes available from a central source? And if this is the case, wouldn't
                        it make more sense to put all the code into a *.vb or *.cs file where it can
                        be centrally referenced?

                        You are right, I think there is something very simple I am misunderstandin g,
                        but for the life of me, I can't locate the answer anwhere.

                        Random

                        "Marina" <someone@nospam .com> wrote in message
                        news:e7UIi%23YH EHA.4032@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                        > I have no idea what you are talking about to be honest.
                        >
                        > The class is already in a namespace - the Inherits attribute is just
                        > referencing. It isn't creating a new namespace or a new class. So I have[/color]
                        no[color=blue]
                        > idea what you are talking about when you ask about namespaces being[/color]
                        written[color=blue]
                        > in central locations.
                        >
                        > You can have any number of pages inherit from the same class - as long as
                        > that class actually exists. In the visual studio model, you would have to
                        > manually do that, because it assume a 1 to 1 ration between pages and code
                        > behind classes.
                        >
                        > If you tried to compiled two classes with the same name into the same
                        > assembly, the compiler would not allow you to do this. The assembly[/color]
                        itself[color=blue]
                        > knows what classes it has, and what namespace each one is in, in it's
                        > manifest.
                        >
                        > I would recommend you start at the very basics of ASP.NET, it sounds like
                        > you are missing some basic concept about how this all works. In your[/color]
                        first[color=blue]
                        > post you asked about the difference between a namespace and a class - so[/color]
                        it[color=blue]
                        > seems like you need to go to the beginning of .NET, and not just into the
                        > middle of ASP.NET.
                        >
                        > "Random" <cipherlad@hotm ail.com> wrote in message
                        > news:uau2myYHEH A.3032@TK2MSFTN GP09.phx.gbl...[color=green]
                        > > Okay, that clarifies the "Inherits" vs. "Imports" question very well.
                        > > Thanks.
                        > >
                        > > As far as the namespace being available in the assembly, though, let me[/color]
                        > give[color=green]
                        > > you an example...
                        > >
                        > > Using the portal code I gave before, would I be able to write another[/color][/color]
                        aspx[color=blue][color=green]
                        > > page, use the same "Inherits=<full y qualified class name>" phrasing,[/color]
                        > without[color=green]
                        > > that class being written into the different codebehind page referenced[/color][/color]
                        in[color=blue][color=green]
                        > > the new aspx page?
                        > >
                        > > If yes, why? Shouldn't namespaces be written in a more centrally[/color]
                        > referenced[color=green]
                        > > file?
                        > >
                        > > If no, then how can the assembly keep track of all the declared[/color]
                        > namespaces?[color=green]
                        > > And what would it do if two or more codebehind references had the same
                        > > namespace and class written in them?
                        > >
                        > > Random
                        > >
                        > > "Marina" <someone@nospam .com> wrote in message
                        > > news:eqT6TmYHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=darkred]
                        > > > This inherits attribute, refers to the name of the class this page[/color]
                        > > inherits[color=darkred]
                        > > > from. The class's name is CDefault, but it is located in the
                        > > > ASPNET.StarterK it.Portal namespace, and so the namespace has to[/color][/color][/color]
                        preceed[color=blue][color=green]
                        > > it.[color=darkred]
                        > > >
                        > > > At runtime, asp.net looks for a class with the name in the inherits
                        > > > attribute.
                        > > >
                        > > > This has nothing to do with projects, or namespaces being available.[/color][/color][/color]
                        It[color=blue]
                        > is[color=green][color=darkred]
                        > > > just the fully qualified name of the class.
                        > > >
                        > > > "Random" <cipherlad@hotm ail.com> wrote in message
                        > > > news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...
                        > > > > Hmm. I'm trying to teach myself from examples and tutorials and[/color][/color]
                        > books.[color=green][color=darkred]
                        > > > > Specifically in this case, I'm trying to learn from the MS
                        > > > PortalStarterKi t.
                        > > > > Specifically, the default page in that example has as the first line[/color][/color]
                        > in[color=green][color=darkred]
                        > > > > default.aspx:
                        > > > >
                        > > > > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"
                        > > > AutoEventWireup ="false"
                        > > > > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
                        > > > >
                        > > > > The codebehind page has:
                        > > > >
                        > > > > Namespace ASPNET.StarterK it.Portal
                        > > > > Public Class CDefault
                        > > > > Inherits System.Web.UI.P age
                        > > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e[/color][/color]
                        > As[color=green][color=darkred]
                        > > > > System.EventArg s) Handles MyBase.Load
                        > > > > <code here>
                        > > > > End Sub
                        > > > > End Class
                        > > > > End Namespace
                        > > > >
                        > > > > I'm trying to find out how and why this works the way that it does.[/color]
                        > > It's[color=darkred]
                        > > > > more complex than the examples given by tutorials and books.
                        > > > >
                        > > > > And again, I'm trying to figure out how the namespace declared here[/color]
                        > > makes[color=darkred]
                        > > > > it's way into the assembly. And because it does, somehow, does that[/color]
                        > > make[color=darkred]
                        > > > it
                        > > > > available through the entire project?
                        > > > >
                        > > > > Random
                        > > > >
                        > > > > "Marina" <someone@nospam .com> wrote in message
                        > > > > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..
                        > > > > > First of all, namespaces can be used with the 'Imports' keyword,[/color][/color][/color]
                        so[color=blue]
                        > as[color=green][color=darkred]
                        > > > not
                        > > > > > have to write out the full namespace for every class, not the[/color]
                        > > 'Inherits'[color=darkred]
                        > > > > > attribute.
                        > > > > >
                        > > > > > Think of namespaces as folders in your file system, and classes as[/color][/color]
                        > the[color=green][color=darkred]
                        > > > > files
                        > > > > > in them. So a namespace itself isn't anything but an[/color][/color][/color]
                        organizational[color=blue][color=green][color=darkred]
                        > > > > > container for classes - just as a folder is just a container for[/color]
                        > > files.[color=darkred]
                        > > > > > Classes are the actual things that you instantiate, and call[/color][/color][/color]
                        methods[color=blue][color=green]
                        > > on.[color=darkred]
                        > > > > >
                        > > > > > I didn't really understand your questions. I think they all stem[/color][/color]
                        > from[color=green][color=darkred]
                        > > > not
                        > > > > > understanding what a namespace actually is.
                        > > > > >
                        > > > > > "Random" <cipherlad@hotm ail.com> wrote in message
                        > > > > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...
                        > > > > > > I'm confused about the proper use and usefulness of namespaces.[/color][/color][/color]
                        I[color=blue][color=green][color=darkred]
                        > > > > beleive
                        > > > > > I
                        > > > > > > understand the purpose is so the developer can put classes[/color][/color][/color]
                        within[color=blue][color=green][color=darkred]
                        > > > > > namespaces
                        > > > > > > to essentially organize your code. And I understand that you[/color]
                        > > declare[color=darkred]
                        > > > > your
                        > > > > > > intention to use a namespace within a page through the[/color][/color][/color]
                        "Inherits"[color=blue][color=green][color=darkred]
                        > > > > > attribute.
                        > > > > > > I know that using "Inherits" isn't absolutely necessary, it's[/color][/color][/color]
                        just[color=blue][color=green][color=darkred]
                        > > > > > > recommended so the developer doesn't have to type out the entire
                        > > > > namespace
                        > > > > > > in code. I know that namespaces have to appear in the project
                        > > > assembly,
                        > > > > > > however...
                        > > > > > >
                        > > > > > > How does the assembly find a namespace that the developer has
                        > > > > written????
                        > > > > > > In all the examples I've seen, namespaces have been written in
                        > > > > codebehind
                        > > > > > > pages. How does this make them accessible to the entire[/color][/color][/color]
                        project?[color=blue][color=green][color=darkred]
                        > > > > What's
                        > > > > > to
                        > > > > > > prevent a duplicate namespace from being written in a different
                        > > > > codebehind
                        > > > > > > page? Is there a better place to write all the project[/color][/color][/color]
                        namespaces[color=blue][color=green]
                        > > for[color=darkred]
                        > > > > > more
                        > > > > > > centralized accessibility?
                        > > > > > >
                        > > > > > > And finally, how do namespaces DIFFER from classes?
                        > > > > > >
                        > > > > > > Random
                        > > > > > >
                        > > > > > >
                        > > > > >
                        > > > > >
                        > > > >
                        > > > >
                        > > >
                        > > >[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]


                        Comment

                        • Random

                          #13
                          Re: Namespaces - broad question

                          I know you are not trying to offend, Marina, but I am an experienced
                          programmer, just new to .NET, and I have read a lot, from the basics. I am
                          disappointed that a lot of the 'beginner' material has been unhelpful when
                          it comes to an architectural overview of ASP.NET, which is what I am trying
                          to clarify here. I thought that by asking 'basic' questions, I might get a
                          better understanding of how things fit into the whole. So please be patient
                          with me in this.

                          I realize that while Visual Studio automatically encourages a 1 to 1
                          relationship between aspx and codebehind pages, this does not necessarily
                          need to be the case. I also realize that errors would occur during
                          compiling if the same class was written in different places. What I don't
                          understand is how Visual Studio keeps track in the assembly of where all
                          these written classes are?

                          As another example, what if I wrote an aspx page that inherited a class
                          contained in a codebehind page that was NOT referenced by the aspx page?
                          Since the class is found in the assembly, how would the aspx page know where
                          to look? When the code is all compiled, does it automatically all the
                          classes available from a central source? And if this is the case, wouldn't
                          it make more sense to put all the code into a *.vb or *.cs file where it can
                          be centrally referenced?

                          You are right, I think there is something very simple I am misunderstandin g,
                          but for the life of me, I can't locate the answer anwhere.

                          Random

                          "Marina" <someone@nospam .com> wrote in message
                          news:e7UIi%23YH EHA.4032@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                          > I have no idea what you are talking about to be honest.
                          >
                          > The class is already in a namespace - the Inherits attribute is just
                          > referencing. It isn't creating a new namespace or a new class. So I have[/color]
                          no[color=blue]
                          > idea what you are talking about when you ask about namespaces being[/color]
                          written[color=blue]
                          > in central locations.
                          >
                          > You can have any number of pages inherit from the same class - as long as
                          > that class actually exists. In the visual studio model, you would have to
                          > manually do that, because it assume a 1 to 1 ration between pages and code
                          > behind classes.
                          >
                          > If you tried to compiled two classes with the same name into the same
                          > assembly, the compiler would not allow you to do this. The assembly[/color]
                          itself[color=blue]
                          > knows what classes it has, and what namespace each one is in, in it's
                          > manifest.
                          >
                          > I would recommend you start at the very basics of ASP.NET, it sounds like
                          > you are missing some basic concept about how this all works. In your[/color]
                          first[color=blue]
                          > post you asked about the difference between a namespace and a class - so[/color]
                          it[color=blue]
                          > seems like you need to go to the beginning of .NET, and not just into the
                          > middle of ASP.NET.
                          >
                          > "Random" <cipherlad@hotm ail.com> wrote in message
                          > news:uau2myYHEH A.3032@TK2MSFTN GP09.phx.gbl...[color=green]
                          > > Okay, that clarifies the "Inherits" vs. "Imports" question very well.
                          > > Thanks.
                          > >
                          > > As far as the namespace being available in the assembly, though, let me[/color]
                          > give[color=green]
                          > > you an example...
                          > >
                          > > Using the portal code I gave before, would I be able to write another[/color][/color]
                          aspx[color=blue][color=green]
                          > > page, use the same "Inherits=<full y qualified class name>" phrasing,[/color]
                          > without[color=green]
                          > > that class being written into the different codebehind page referenced[/color][/color]
                          in[color=blue][color=green]
                          > > the new aspx page?
                          > >
                          > > If yes, why? Shouldn't namespaces be written in a more centrally[/color]
                          > referenced[color=green]
                          > > file?
                          > >
                          > > If no, then how can the assembly keep track of all the declared[/color]
                          > namespaces?[color=green]
                          > > And what would it do if two or more codebehind references had the same
                          > > namespace and class written in them?
                          > >
                          > > Random
                          > >
                          > > "Marina" <someone@nospam .com> wrote in message
                          > > news:eqT6TmYHEH A.2668@TK2MSFTN GP10.phx.gbl...[color=darkred]
                          > > > This inherits attribute, refers to the name of the class this page[/color]
                          > > inherits[color=darkred]
                          > > > from. The class's name is CDefault, but it is located in the
                          > > > ASPNET.StarterK it.Portal namespace, and so the namespace has to[/color][/color][/color]
                          preceed[color=blue][color=green]
                          > > it.[color=darkred]
                          > > >
                          > > > At runtime, asp.net looks for a class with the name in the inherits
                          > > > attribute.
                          > > >
                          > > > This has nothing to do with projects, or namespaces being available.[/color][/color][/color]
                          It[color=blue]
                          > is[color=green][color=darkred]
                          > > > just the fully qualified name of the class.
                          > > >
                          > > > "Random" <cipherlad@hotm ail.com> wrote in message
                          > > > news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...
                          > > > > Hmm. I'm trying to teach myself from examples and tutorials and[/color][/color]
                          > books.[color=green][color=darkred]
                          > > > > Specifically in this case, I'm trying to learn from the MS
                          > > > PortalStarterKi t.
                          > > > > Specifically, the default page in that example has as the first line[/color][/color]
                          > in[color=green][color=darkred]
                          > > > > default.aspx:
                          > > > >
                          > > > > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"
                          > > > AutoEventWireup ="false"
                          > > > > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
                          > > > >
                          > > > > The codebehind page has:
                          > > > >
                          > > > > Namespace ASPNET.StarterK it.Portal
                          > > > > Public Class CDefault
                          > > > > Inherits System.Web.UI.P age
                          > > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e[/color][/color]
                          > As[color=green][color=darkred]
                          > > > > System.EventArg s) Handles MyBase.Load
                          > > > > <code here>
                          > > > > End Sub
                          > > > > End Class
                          > > > > End Namespace
                          > > > >
                          > > > > I'm trying to find out how and why this works the way that it does.[/color]
                          > > It's[color=darkred]
                          > > > > more complex than the examples given by tutorials and books.
                          > > > >
                          > > > > And again, I'm trying to figure out how the namespace declared here[/color]
                          > > makes[color=darkred]
                          > > > > it's way into the assembly. And because it does, somehow, does that[/color]
                          > > make[color=darkred]
                          > > > it
                          > > > > available through the entire project?
                          > > > >
                          > > > > Random
                          > > > >
                          > > > > "Marina" <someone@nospam .com> wrote in message
                          > > > > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..
                          > > > > > First of all, namespaces can be used with the 'Imports' keyword,[/color][/color][/color]
                          so[color=blue]
                          > as[color=green][color=darkred]
                          > > > not
                          > > > > > have to write out the full namespace for every class, not the[/color]
                          > > 'Inherits'[color=darkred]
                          > > > > > attribute.
                          > > > > >
                          > > > > > Think of namespaces as folders in your file system, and classes as[/color][/color]
                          > the[color=green][color=darkred]
                          > > > > files
                          > > > > > in them. So a namespace itself isn't anything but an[/color][/color][/color]
                          organizational[color=blue][color=green][color=darkred]
                          > > > > > container for classes - just as a folder is just a container for[/color]
                          > > files.[color=darkred]
                          > > > > > Classes are the actual things that you instantiate, and call[/color][/color][/color]
                          methods[color=blue][color=green]
                          > > on.[color=darkred]
                          > > > > >
                          > > > > > I didn't really understand your questions. I think they all stem[/color][/color]
                          > from[color=green][color=darkred]
                          > > > not
                          > > > > > understanding what a namespace actually is.
                          > > > > >
                          > > > > > "Random" <cipherlad@hotm ail.com> wrote in message
                          > > > > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...
                          > > > > > > I'm confused about the proper use and usefulness of namespaces.[/color][/color][/color]
                          I[color=blue][color=green][color=darkred]
                          > > > > beleive
                          > > > > > I
                          > > > > > > understand the purpose is so the developer can put classes[/color][/color][/color]
                          within[color=blue][color=green][color=darkred]
                          > > > > > namespaces
                          > > > > > > to essentially organize your code. And I understand that you[/color]
                          > > declare[color=darkred]
                          > > > > your
                          > > > > > > intention to use a namespace within a page through the[/color][/color][/color]
                          "Inherits"[color=blue][color=green][color=darkred]
                          > > > > > attribute.
                          > > > > > > I know that using "Inherits" isn't absolutely necessary, it's[/color][/color][/color]
                          just[color=blue][color=green][color=darkred]
                          > > > > > > recommended so the developer doesn't have to type out the entire
                          > > > > namespace
                          > > > > > > in code. I know that namespaces have to appear in the project
                          > > > assembly,
                          > > > > > > however...
                          > > > > > >
                          > > > > > > How does the assembly find a namespace that the developer has
                          > > > > written????
                          > > > > > > In all the examples I've seen, namespaces have been written in
                          > > > > codebehind
                          > > > > > > pages. How does this make them accessible to the entire[/color][/color][/color]
                          project?[color=blue][color=green][color=darkred]
                          > > > > What's
                          > > > > > to
                          > > > > > > prevent a duplicate namespace from being written in a different
                          > > > > codebehind
                          > > > > > > page? Is there a better place to write all the project[/color][/color][/color]
                          namespaces[color=blue][color=green]
                          > > for[color=darkred]
                          > > > > > more
                          > > > > > > centralized accessibility?
                          > > > > > >
                          > > > > > > And finally, how do namespaces DIFFER from classes?
                          > > > > > >
                          > > > > > > Random
                          > > > > > >
                          > > > > > >
                          > > > > >
                          > > > > >
                          > > > >
                          > > > >
                          > > >
                          > > >[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          • Marina

                            #14
                            Re: Namespaces - broad question

                            My point was about the understandings of .NET, not your experience with
                            anything else. I think if the distinction between what a namespace is, and
                            what a class is, is unclear, then you can't really go anywhere until it is.

                            When VS.NEt compiles your web project, it places all the classes in one DLL.
                            When a page is requested, the class in this Inherits attribute is looked for
                            in the bin directory - so it has to be compiled into one of the DLL's that
                            is located in that directory. This is done by the asp.net process at run
                            time - nothing to do with visual studio. Visual studio doesn't keep track
                            of anything - it just compiles all the classes in the project into one
                            assembly. If there are duplicate class names, then the compilation process
                            will fail.

                            I am still not understanding what you think is being kept track of and
                            where. Or what you ask when you talk about keeping the code in .vb and .cs
                            files - the source is already in those files. What does "what if I wrote an
                            aspx page that inherited a class contained in a codebehind page that was NOT
                            referenced by the aspx page?" mean? How can you write a page that inherits
                            from a codebehind class - but yet not reference it?

                            Do you have a book that you are reading about this from, that is not
                            explaining it well?


                            "Random" <cipherlad@hotm ail.com> wrote in message
                            news:%23DVrHZZH EHA.2624@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                            > I know you are not trying to offend, Marina, but I am an experienced
                            > programmer, just new to .NET, and I have read a lot, from the basics. I[/color]
                            am[color=blue]
                            > disappointed that a lot of the 'beginner' material has been unhelpful when
                            > it comes to an architectural overview of ASP.NET, which is what I am[/color]
                            trying[color=blue]
                            > to clarify here. I thought that by asking 'basic' questions, I might get[/color]
                            a[color=blue]
                            > better understanding of how things fit into the whole. So please be[/color]
                            patient[color=blue]
                            > with me in this.
                            >
                            > I realize that while Visual Studio automatically encourages a 1 to 1
                            > relationship between aspx and codebehind pages, this does not necessarily
                            > need to be the case. I also realize that errors would occur during
                            > compiling if the same class was written in different places. What I don't
                            > understand is how Visual Studio keeps track in the assembly of where all
                            > these written classes are?
                            >
                            > As another example, what if I wrote an aspx page that inherited a class
                            > contained in a codebehind page that was NOT referenced by the aspx page?
                            > Since the class is found in the assembly, how would the aspx page know[/color]
                            where[color=blue]
                            > to look? When the code is all compiled, does it automatically all the
                            > classes available from a central source? And if this is the case,[/color]
                            wouldn't[color=blue]
                            > it make more sense to put all the code into a *.vb or *.cs file where it[/color]
                            can[color=blue]
                            > be centrally referenced?
                            >
                            > You are right, I think there is something very simple I am[/color]
                            misunderstandin g,[color=blue]
                            > but for the life of me, I can't locate the answer anwhere.
                            >
                            > Random
                            >
                            > "Marina" <someone@nospam .com> wrote in message
                            > news:e7UIi%23YH EHA.4032@TK2MSF TNGP12.phx.gbl. ..[color=green]
                            > > I have no idea what you are talking about to be honest.
                            > >
                            > > The class is already in a namespace - the Inherits attribute is just
                            > > referencing. It isn't creating a new namespace or a new class. So I[/color][/color]
                            have[color=blue]
                            > no[color=green]
                            > > idea what you are talking about when you ask about namespaces being[/color]
                            > written[color=green]
                            > > in central locations.
                            > >
                            > > You can have any number of pages inherit from the same class - as long[/color][/color]
                            as[color=blue][color=green]
                            > > that class actually exists. In the visual studio model, you would have[/color][/color]
                            to[color=blue][color=green]
                            > > manually do that, because it assume a 1 to 1 ration between pages and[/color][/color]
                            code[color=blue][color=green]
                            > > behind classes.
                            > >
                            > > If you tried to compiled two classes with the same name into the same
                            > > assembly, the compiler would not allow you to do this. The assembly[/color]
                            > itself[color=green]
                            > > knows what classes it has, and what namespace each one is in, in it's
                            > > manifest.
                            > >
                            > > I would recommend you start at the very basics of ASP.NET, it sounds[/color][/color]
                            like[color=blue][color=green]
                            > > you are missing some basic concept about how this all works. In your[/color]
                            > first[color=green]
                            > > post you asked about the difference between a namespace and a class - so[/color]
                            > it[color=green]
                            > > seems like you need to go to the beginning of .NET, and not just into[/color][/color]
                            the[color=blue][color=green]
                            > > middle of ASP.NET.
                            > >
                            > > "Random" <cipherlad@hotm ail.com> wrote in message
                            > > news:uau2myYHEH A.3032@TK2MSFTN GP09.phx.gbl...[color=darkred]
                            > > > Okay, that clarifies the "Inherits" vs. "Imports" question very well.
                            > > > Thanks.
                            > > >
                            > > > As far as the namespace being available in the assembly, though, let[/color][/color][/color]
                            me[color=blue][color=green]
                            > > give[color=darkred]
                            > > > you an example...
                            > > >
                            > > > Using the portal code I gave before, would I be able to write another[/color][/color]
                            > aspx[color=green][color=darkred]
                            > > > page, use the same "Inherits=<full y qualified class name>" phrasing,[/color]
                            > > without[color=darkred]
                            > > > that class being written into the different codebehind page referenced[/color][/color]
                            > in[color=green][color=darkred]
                            > > > the new aspx page?
                            > > >
                            > > > If yes, why? Shouldn't namespaces be written in a more centrally[/color]
                            > > referenced[color=darkred]
                            > > > file?
                            > > >
                            > > > If no, then how can the assembly keep track of all the declared[/color]
                            > > namespaces?[color=darkred]
                            > > > And what would it do if two or more codebehind references had the same
                            > > > namespace and class written in them?
                            > > >
                            > > > Random
                            > > >
                            > > > "Marina" <someone@nospam .com> wrote in message
                            > > > news:eqT6TmYHEH A.2668@TK2MSFTN GP10.phx.gbl...
                            > > > > This inherits attribute, refers to the name of the class this page
                            > > > inherits
                            > > > > from. The class's name is CDefault, but it is located in the
                            > > > > ASPNET.StarterK it.Portal namespace, and so the namespace has to[/color][/color]
                            > preceed[color=green][color=darkred]
                            > > > it.
                            > > > >
                            > > > > At runtime, asp.net looks for a class with the name in the inherits
                            > > > > attribute.
                            > > > >
                            > > > > This has nothing to do with projects, or namespaces being available.[/color][/color]
                            > It[color=green]
                            > > is[color=darkred]
                            > > > > just the fully qualified name of the class.
                            > > > >
                            > > > > "Random" <cipherlad@hotm ail.com> wrote in message
                            > > > > news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...
                            > > > > > Hmm. I'm trying to teach myself from examples and tutorials and[/color]
                            > > books.[color=darkred]
                            > > > > > Specifically in this case, I'm trying to learn from the MS
                            > > > > PortalStarterKi t.
                            > > > > > Specifically, the default page in that example has as the first[/color][/color][/color]
                            line[color=blue][color=green]
                            > > in[color=darkred]
                            > > > > > default.aspx:
                            > > > > >
                            > > > > > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"
                            > > > > AutoEventWireup ="false"
                            > > > > > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
                            > > > > >
                            > > > > > The codebehind page has:
                            > > > > >
                            > > > > > Namespace ASPNET.StarterK it.Portal
                            > > > > > Public Class CDefault
                            > > > > > Inherits System.Web.UI.P age
                            > > > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal[/color][/color][/color]
                            e[color=blue][color=green]
                            > > As[color=darkred]
                            > > > > > System.EventArg s) Handles MyBase.Load
                            > > > > > <code here>
                            > > > > > End Sub
                            > > > > > End Class
                            > > > > > End Namespace
                            > > > > >
                            > > > > > I'm trying to find out how and why this works the way that it[/color][/color][/color]
                            does.[color=blue][color=green][color=darkred]
                            > > > It's
                            > > > > > more complex than the examples given by tutorials and books.
                            > > > > >
                            > > > > > And again, I'm trying to figure out how the namespace declared[/color][/color][/color]
                            here[color=blue][color=green][color=darkred]
                            > > > makes
                            > > > > > it's way into the assembly. And because it does, somehow, does[/color][/color][/color]
                            that[color=blue][color=green][color=darkred]
                            > > > make
                            > > > > it
                            > > > > > available through the entire project?
                            > > > > >
                            > > > > > Random
                            > > > > >
                            > > > > > "Marina" <someone@nospam .com> wrote in message
                            > > > > > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..
                            > > > > > > First of all, namespaces can be used with the 'Imports' keyword,[/color][/color]
                            > so[color=green]
                            > > as[color=darkred]
                            > > > > not
                            > > > > > > have to write out the full namespace for every class, not the
                            > > > 'Inherits'
                            > > > > > > attribute.
                            > > > > > >
                            > > > > > > Think of namespaces as folders in your file system, and classes[/color][/color][/color]
                            as[color=blue][color=green]
                            > > the[color=darkred]
                            > > > > > files
                            > > > > > > in them. So a namespace itself isn't anything but an[/color][/color]
                            > organizational[color=green][color=darkred]
                            > > > > > > container for classes - just as a folder is just a container for
                            > > > files.
                            > > > > > > Classes are the actual things that you instantiate, and call[/color][/color]
                            > methods[color=green][color=darkred]
                            > > > on.
                            > > > > > >
                            > > > > > > I didn't really understand your questions. I think they all stem[/color]
                            > > from[color=darkred]
                            > > > > not
                            > > > > > > understanding what a namespace actually is.
                            > > > > > >
                            > > > > > > "Random" <cipherlad@hotm ail.com> wrote in message
                            > > > > > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...
                            > > > > > > > I'm confused about the proper use and usefulness of[/color][/color][/color]
                            namespaces.[color=blue]
                            > I[color=green][color=darkred]
                            > > > > > beleive
                            > > > > > > I
                            > > > > > > > understand the purpose is so the developer can put classes[/color][/color]
                            > within[color=green][color=darkred]
                            > > > > > > namespaces
                            > > > > > > > to essentially organize your code. And I understand that you
                            > > > declare
                            > > > > > your
                            > > > > > > > intention to use a namespace within a page through the[/color][/color]
                            > "Inherits"[color=green][color=darkred]
                            > > > > > > attribute.
                            > > > > > > > I know that using "Inherits" isn't absolutely necessary, it's[/color][/color]
                            > just[color=green][color=darkred]
                            > > > > > > > recommended so the developer doesn't have to type out the[/color][/color][/color]
                            entire[color=blue][color=green][color=darkred]
                            > > > > > namespace
                            > > > > > > > in code. I know that namespaces have to appear in the project
                            > > > > assembly,
                            > > > > > > > however...
                            > > > > > > >
                            > > > > > > > How does the assembly find a namespace that the developer has
                            > > > > > written????
                            > > > > > > > In all the examples I've seen, namespaces have been written in
                            > > > > > codebehind
                            > > > > > > > pages. How does this make them accessible to the entire[/color][/color]
                            > project?[color=green][color=darkred]
                            > > > > > What's
                            > > > > > > to
                            > > > > > > > prevent a duplicate namespace from being written in a[/color][/color][/color]
                            different[color=blue][color=green][color=darkred]
                            > > > > > codebehind
                            > > > > > > > page? Is there a better place to write all the project[/color][/color]
                            > namespaces[color=green][color=darkred]
                            > > > for
                            > > > > > > more
                            > > > > > > > centralized accessibility?
                            > > > > > > >
                            > > > > > > > And finally, how do namespaces DIFFER from classes?
                            > > > > > > >
                            > > > > > > > Random
                            > > > > > > >
                            > > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > >
                            > > > > >
                            > > > >
                            > > > >
                            > > >
                            > > >[/color]
                            > >
                            > >[/color]
                            >
                            >[/color]


                            Comment

                            • Marina

                              #15
                              Re: Namespaces - broad question

                              My point was about the understandings of .NET, not your experience with
                              anything else. I think if the distinction between what a namespace is, and
                              what a class is, is unclear, then you can't really go anywhere until it is.

                              When VS.NEt compiles your web project, it places all the classes in one DLL.
                              When a page is requested, the class in this Inherits attribute is looked for
                              in the bin directory - so it has to be compiled into one of the DLL's that
                              is located in that directory. This is done by the asp.net process at run
                              time - nothing to do with visual studio. Visual studio doesn't keep track
                              of anything - it just compiles all the classes in the project into one
                              assembly. If there are duplicate class names, then the compilation process
                              will fail.

                              I am still not understanding what you think is being kept track of and
                              where. Or what you ask when you talk about keeping the code in .vb and .cs
                              files - the source is already in those files. What does "what if I wrote an
                              aspx page that inherited a class contained in a codebehind page that was NOT
                              referenced by the aspx page?" mean? How can you write a page that inherits
                              from a codebehind class - but yet not reference it?

                              Do you have a book that you are reading about this from, that is not
                              explaining it well?


                              "Random" <cipherlad@hotm ail.com> wrote in message
                              news:%23DVrHZZH EHA.2624@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                              > I know you are not trying to offend, Marina, but I am an experienced
                              > programmer, just new to .NET, and I have read a lot, from the basics. I[/color]
                              am[color=blue]
                              > disappointed that a lot of the 'beginner' material has been unhelpful when
                              > it comes to an architectural overview of ASP.NET, which is what I am[/color]
                              trying[color=blue]
                              > to clarify here. I thought that by asking 'basic' questions, I might get[/color]
                              a[color=blue]
                              > better understanding of how things fit into the whole. So please be[/color]
                              patient[color=blue]
                              > with me in this.
                              >
                              > I realize that while Visual Studio automatically encourages a 1 to 1
                              > relationship between aspx and codebehind pages, this does not necessarily
                              > need to be the case. I also realize that errors would occur during
                              > compiling if the same class was written in different places. What I don't
                              > understand is how Visual Studio keeps track in the assembly of where all
                              > these written classes are?
                              >
                              > As another example, what if I wrote an aspx page that inherited a class
                              > contained in a codebehind page that was NOT referenced by the aspx page?
                              > Since the class is found in the assembly, how would the aspx page know[/color]
                              where[color=blue]
                              > to look? When the code is all compiled, does it automatically all the
                              > classes available from a central source? And if this is the case,[/color]
                              wouldn't[color=blue]
                              > it make more sense to put all the code into a *.vb or *.cs file where it[/color]
                              can[color=blue]
                              > be centrally referenced?
                              >
                              > You are right, I think there is something very simple I am[/color]
                              misunderstandin g,[color=blue]
                              > but for the life of me, I can't locate the answer anwhere.
                              >
                              > Random
                              >
                              > "Marina" <someone@nospam .com> wrote in message
                              > news:e7UIi%23YH EHA.4032@TK2MSF TNGP12.phx.gbl. ..[color=green]
                              > > I have no idea what you are talking about to be honest.
                              > >
                              > > The class is already in a namespace - the Inherits attribute is just
                              > > referencing. It isn't creating a new namespace or a new class. So I[/color][/color]
                              have[color=blue]
                              > no[color=green]
                              > > idea what you are talking about when you ask about namespaces being[/color]
                              > written[color=green]
                              > > in central locations.
                              > >
                              > > You can have any number of pages inherit from the same class - as long[/color][/color]
                              as[color=blue][color=green]
                              > > that class actually exists. In the visual studio model, you would have[/color][/color]
                              to[color=blue][color=green]
                              > > manually do that, because it assume a 1 to 1 ration between pages and[/color][/color]
                              code[color=blue][color=green]
                              > > behind classes.
                              > >
                              > > If you tried to compiled two classes with the same name into the same
                              > > assembly, the compiler would not allow you to do this. The assembly[/color]
                              > itself[color=green]
                              > > knows what classes it has, and what namespace each one is in, in it's
                              > > manifest.
                              > >
                              > > I would recommend you start at the very basics of ASP.NET, it sounds[/color][/color]
                              like[color=blue][color=green]
                              > > you are missing some basic concept about how this all works. In your[/color]
                              > first[color=green]
                              > > post you asked about the difference between a namespace and a class - so[/color]
                              > it[color=green]
                              > > seems like you need to go to the beginning of .NET, and not just into[/color][/color]
                              the[color=blue][color=green]
                              > > middle of ASP.NET.
                              > >
                              > > "Random" <cipherlad@hotm ail.com> wrote in message
                              > > news:uau2myYHEH A.3032@TK2MSFTN GP09.phx.gbl...[color=darkred]
                              > > > Okay, that clarifies the "Inherits" vs. "Imports" question very well.
                              > > > Thanks.
                              > > >
                              > > > As far as the namespace being available in the assembly, though, let[/color][/color][/color]
                              me[color=blue][color=green]
                              > > give[color=darkred]
                              > > > you an example...
                              > > >
                              > > > Using the portal code I gave before, would I be able to write another[/color][/color]
                              > aspx[color=green][color=darkred]
                              > > > page, use the same "Inherits=<full y qualified class name>" phrasing,[/color]
                              > > without[color=darkred]
                              > > > that class being written into the different codebehind page referenced[/color][/color]
                              > in[color=green][color=darkred]
                              > > > the new aspx page?
                              > > >
                              > > > If yes, why? Shouldn't namespaces be written in a more centrally[/color]
                              > > referenced[color=darkred]
                              > > > file?
                              > > >
                              > > > If no, then how can the assembly keep track of all the declared[/color]
                              > > namespaces?[color=darkred]
                              > > > And what would it do if two or more codebehind references had the same
                              > > > namespace and class written in them?
                              > > >
                              > > > Random
                              > > >
                              > > > "Marina" <someone@nospam .com> wrote in message
                              > > > news:eqT6TmYHEH A.2668@TK2MSFTN GP10.phx.gbl...
                              > > > > This inherits attribute, refers to the name of the class this page
                              > > > inherits
                              > > > > from. The class's name is CDefault, but it is located in the
                              > > > > ASPNET.StarterK it.Portal namespace, and so the namespace has to[/color][/color]
                              > preceed[color=green][color=darkred]
                              > > > it.
                              > > > >
                              > > > > At runtime, asp.net looks for a class with the name in the inherits
                              > > > > attribute.
                              > > > >
                              > > > > This has nothing to do with projects, or namespaces being available.[/color][/color]
                              > It[color=green]
                              > > is[color=darkred]
                              > > > > just the fully qualified name of the class.
                              > > > >
                              > > > > "Random" <cipherlad@hotm ail.com> wrote in message
                              > > > > news:OI$efeYHEH A.548@TK2MSFTNG P09.phx.gbl...
                              > > > > > Hmm. I'm trying to teach myself from examples and tutorials and[/color]
                              > > books.[color=darkred]
                              > > > > > Specifically in this case, I'm trying to learn from the MS
                              > > > > PortalStarterKi t.
                              > > > > > Specifically, the default page in that example has as the first[/color][/color][/color]
                              line[color=blue][color=green]
                              > > in[color=darkred]
                              > > > > > default.aspx:
                              > > > > >
                              > > > > > <%@ Page CodeBehind="Def ault.aspx.vb" language="vb"
                              > > > > AutoEventWireup ="false"
                              > > > > > Inherits="ASPNE T.StarterKit.Po rtal.CDefault" %>
                              > > > > >
                              > > > > > The codebehind page has:
                              > > > > >
                              > > > > > Namespace ASPNET.StarterK it.Portal
                              > > > > > Public Class CDefault
                              > > > > > Inherits System.Web.UI.P age
                              > > > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal[/color][/color][/color]
                              e[color=blue][color=green]
                              > > As[color=darkred]
                              > > > > > System.EventArg s) Handles MyBase.Load
                              > > > > > <code here>
                              > > > > > End Sub
                              > > > > > End Class
                              > > > > > End Namespace
                              > > > > >
                              > > > > > I'm trying to find out how and why this works the way that it[/color][/color][/color]
                              does.[color=blue][color=green][color=darkred]
                              > > > It's
                              > > > > > more complex than the examples given by tutorials and books.
                              > > > > >
                              > > > > > And again, I'm trying to figure out how the namespace declared[/color][/color][/color]
                              here[color=blue][color=green][color=darkred]
                              > > > makes
                              > > > > > it's way into the assembly. And because it does, somehow, does[/color][/color][/color]
                              that[color=blue][color=green][color=darkred]
                              > > > make
                              > > > > it
                              > > > > > available through the entire project?
                              > > > > >
                              > > > > > Random
                              > > > > >
                              > > > > > "Marina" <someone@nospam .com> wrote in message
                              > > > > > news:%23WIkSAYH EHA.2260@TK2MSF TNGP09.phx.gbl. ..
                              > > > > > > First of all, namespaces can be used with the 'Imports' keyword,[/color][/color]
                              > so[color=green]
                              > > as[color=darkred]
                              > > > > not
                              > > > > > > have to write out the full namespace for every class, not the
                              > > > 'Inherits'
                              > > > > > > attribute.
                              > > > > > >
                              > > > > > > Think of namespaces as folders in your file system, and classes[/color][/color][/color]
                              as[color=blue][color=green]
                              > > the[color=darkred]
                              > > > > > files
                              > > > > > > in them. So a namespace itself isn't anything but an[/color][/color]
                              > organizational[color=green][color=darkred]
                              > > > > > > container for classes - just as a folder is just a container for
                              > > > files.
                              > > > > > > Classes are the actual things that you instantiate, and call[/color][/color]
                              > methods[color=green][color=darkred]
                              > > > on.
                              > > > > > >
                              > > > > > > I didn't really understand your questions. I think they all stem[/color]
                              > > from[color=darkred]
                              > > > > not
                              > > > > > > understanding what a namespace actually is.
                              > > > > > >
                              > > > > > > "Random" <cipherlad@hotm ail.com> wrote in message
                              > > > > > > news:uD4r44XHEH A.2668@TK2MSFTN GP10.phx.gbl...
                              > > > > > > > I'm confused about the proper use and usefulness of[/color][/color][/color]
                              namespaces.[color=blue]
                              > I[color=green][color=darkred]
                              > > > > > beleive
                              > > > > > > I
                              > > > > > > > understand the purpose is so the developer can put classes[/color][/color]
                              > within[color=green][color=darkred]
                              > > > > > > namespaces
                              > > > > > > > to essentially organize your code. And I understand that you
                              > > > declare
                              > > > > > your
                              > > > > > > > intention to use a namespace within a page through the[/color][/color]
                              > "Inherits"[color=green][color=darkred]
                              > > > > > > attribute.
                              > > > > > > > I know that using "Inherits" isn't absolutely necessary, it's[/color][/color]
                              > just[color=green][color=darkred]
                              > > > > > > > recommended so the developer doesn't have to type out the[/color][/color][/color]
                              entire[color=blue][color=green][color=darkred]
                              > > > > > namespace
                              > > > > > > > in code. I know that namespaces have to appear in the project
                              > > > > assembly,
                              > > > > > > > however...
                              > > > > > > >
                              > > > > > > > How does the assembly find a namespace that the developer has
                              > > > > > written????
                              > > > > > > > In all the examples I've seen, namespaces have been written in
                              > > > > > codebehind
                              > > > > > > > pages. How does this make them accessible to the entire[/color][/color]
                              > project?[color=green][color=darkred]
                              > > > > > What's
                              > > > > > > to
                              > > > > > > > prevent a duplicate namespace from being written in a[/color][/color][/color]
                              different[color=blue][color=green][color=darkred]
                              > > > > > codebehind
                              > > > > > > > page? Is there a better place to write all the project[/color][/color]
                              > namespaces[color=green][color=darkred]
                              > > > for
                              > > > > > > more
                              > > > > > > > centralized accessibility?
                              > > > > > > >
                              > > > > > > > And finally, how do namespaces DIFFER from classes?
                              > > > > > > >
                              > > > > > > > Random
                              > > > > > > >
                              > > > > > > >
                              > > > > > >
                              > > > > > >
                              > > > > >
                              > > > > >
                              > > > >
                              > > > >
                              > > >
                              > > >[/color]
                              > >
                              > >[/color]
                              >
                              >[/color]


                              Comment

                              Working...