Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

ASP.NET: Defining Imports

From Wiki

Jump to: navigation, search

Summary: Defining Imports

If you want to access a certain object in a namespace, you need to provide the full path to it e.g.

  1. Dim dt as New System.Data.DataTable

However, by adding an imports statement to the top of your class:

  1. Imports System.Data

you can now just write:

  1. Dim dt as New DataTable

However, you need to do this in every page or class where you need to reference the object. You can extend this functionality by adding the imports statements to the web.config file and they will then be available in every page or class:

  1. <pages>
  2.  <namespaces>
  3.   <clear/>
  4.   <add namespace="System"/>
  5.   <add namespace="System.Collections"/>
  6.   <add namespace="System.Collections.Specialized"/>
  7.   <add namespace="System.Configuration"/>
  8.   <add namespace="System.Text"/>
  9.   <add namespace="System.Text.RegularExpressions"/>
  10.   <add namespace="System.Web"/>
  11.   <add namespace="System.Web.Caching"/>
  12.   <add namespace="System.Web.SessionState"/>
  13.   <add namespace="System.Web.Security"/>
  14.   <add namespace="System.Web.Profile"/>
  15.   <add namespace="System.Web.UI"/>
  16.   <add namespace="System.Web.UI.WebControls"/>
  17.   <add namespace="System.Web.UI.WebControls.WebParts"/>
  18.   <add namespace="System.Web.UI.HtmlControls"/>
  19.  </namespaces>
  20. </pages>

502 Rating: 3.7/5 (3 votes cast)