Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

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.0/5 (8 votes cast)