ComponentOne Splitter for ASP.NET AJAX: ComponentOne Splitter for ASP.NET AJAX Overview > Namespaces

Namespaces

Namespaces organize the objects defined in an assembly. Assemblies can contain multiple namespaces, which can in turn contain other namespaces. Namespaces prevent ambiguity and simplify references when using large groups of objects such as class libraries.

The general namespace for ComponentOne Web products is C1.Web. The following code fragment shows how to declare a C1TreeView (which is one of the core Studio for ASP.NET AJAX classes) using the fully qualified name for this class:

      Visual Basic

Dim TreeView As C1.Web.UI.Controls.C1TreeView

      C#

C1.Web.UI.Controls.C1TreeView TreeView;

Namespaces address a problem sometimes known as namespace pollution, in which the developer of a class library is hampered by the use of similar names in another library. These conflicts with existing components are sometimes called name collisions.

Fully qualified names are object references that are prefixed with the name of the namespace where the object is defined. You can use objects defined in other projects if you create a reference to the class (by choosing Add Reference from the Project menu) and then use the fully qualified name for the object in your code.

Fully qualified names prevent naming conflicts because the compiler can always determine which object is being used. However, the names themselves can get long and cumbersome. To get around this, you can use the Imports statement (using in C#) to define an alias — an abbreviated name you can use in place of a fully qualified name. For example, the following code snippet creates aliases for two fully qualified names, and uses these aliases to define two objects:

      Visual Basic

Imports C1TreeView = C1.Web.UI.Controls.C1TreeView

Imports MyTreeView = MyProject.Objects.C1TreeView

 

Dim wm1 As C1TreeView

Dim wm2 As MyTreeViewMenu

      C#

using C1TreeView = C1.Web.UI.Controls.C1TreeView;

using MyTreeView = MyProject.Objects.C1TreeView;

 

 C1TreeView wm1;

 MyTreeView wm2;

If you use the Imports statement without an alias, you can use all the names in that namespace without qualification provided they are unique to the project.

When creating AJAX-Enabled ASP.NET projects, Visual Studio 2005 gives you the option of creating a Web site project or a Web application project.

Creating an AJAX-Enabled ASP.NET Project requires installation of Microsoft ASP.NET AJAX Extensions, which can be found at http://ajax.asp.net/. For more information about Microsoft ASP.NET AJAX Extensions, see Microsoft's ASP.Net AJAX Web site. Creating a Web application project requires installation of a Visual Studio 2005 update and add-in, which can be found at http://msdn.microsoft.com/. See Microsoft's Web site for more detailed information and comparisons on Web site and Web application projects.

The steps for creating both types of projects have been provided for your convenience in the Creating an AJAX-Enabled ASP.NET Project topic.


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.