IntelliSense makes it easier to complete the following tasks:
Find member information.
Insert language elements directly into your code.
Maintain your context without having to leave the code editor.
This topic contains the following sections:
Determining IntelliSense Context
Processing IntelliSense Information
For more information about the IntelliSense functionality of Visual Studio, see Using IntelliSense.
Determining IntelliSense Context
Your current script context is created based on the following items:
Functions that are defined in all script blocks in the active document. Inline script blocks are supported in files that have the file-name extensions .aspx., .ascx, .master, .html, and .htm.
script elements with src attributes that point to another script file. The target script file must have the file-name extension .js.
Reference groups for global objects, IntelliSense extensions, or delay-loaded script files.
References to XML Web services.
The Microsoft Ajax Library, if you are working in an AJAX-enabled ASP.NET Web application.
IntelliSense is not supported for script that is in event-handler attributes on HTML elements, or that is defined in href attributes.
Processing IntelliSense Information
Traverses the list and collects type information and other relevant data from each file.
Monitors the files for changes that might affect the IntelliSense list and updates the list as needed. Scripts on remote stores (such as those referenced using HTTP) do not get monitored.
Document Object Model (DOM) elements
User-defined variables, functions, and objects
Objects defined in external files using references such as script references, reference directives, and reference groups.
Objects specified in XML documentation comments, such as parameters and fields.
ASP.NET AJAX objects
When IntelliSense is unable to determine the type of an object, it provides options for statement completion using identifiers in the active document. For more information, see Statement Completion for Identifiers.
HTML DOM Elements
User-defined Variables, Functions, and Objects
For more information about user-defined variables, functions, and objects, see Creating Your Own Objects on the MSDN Web site.
External File References
You can include various types of external file references to achieve IntelliSense support in your code. External file references may be script references, reference directives, or they can be specified using reference groups.
Instead of writing all client script in a page, you can reference external files that include scripting code. This makes it easier for you to reuse code between pages, and it enables client script to be cached by the browser.
If you are not working with an ASP.NET AJAX-enabled Web page, you can reference an external script file by using the src attribute in the opening tag of a script element. The src attribute specifies the URL to an external file that contains the source code or data.
The following example shows markup that uses the src attribute in a <script> tag to reference a script file.
A reference directive enables Visual Studio to establish a relationship between the script you are currently editing and other scripts. The reference directive lets you include a script file in the scripting context of the current script file. This enables IntelliSense to reference externally defined functions, types, and fields as you code.
You create a reference directive in the form of an XML comment. The directive must be declared earlier in the file than any script. A reference directive can include a disk-based script reference, an assembly-based script reference, a service-based script reference, or a page-based script reference.
The following example shows examples of using disk-based reference directives. In the first example, the language service looks for the file in the same folder that contains the project file (for example, .jsproj).
/// <reference path="ScriptFile1.js" />
/// <reference path="Scripts/ScriptFile2.js" />
/// <reference path="../ScriptFile3.js" />
/// <reference path="~/Scripts/ScriptFile4.js" />
The following example shows how to create a reference to an assembly-based script.
/// <reference name "Ajax.js" assembly="System.Web.Extensions, ..." />
The following example shows how to reference service-based script:
/// <reference path="MyService.asmx" />
/// <reference path="Services/MyService.asmx" />
/// <reference path="../MyService.asmx" />
/// <reference path="~/Services/MyService.asmx" />
The following example shows how to reference page-based script.
/// <reference path="Default.aspx" />
/// <reference path="Admin/Default.aspx" />
/// <reference path="../Default.aspx" />
/// <reference path="~/Admin/Default.aspx" />
The following rules apply to a reference directive.
The reference XML comment must be declared before any script.
You must use XML comments syntax with three slashes. References made by using standard comments syntax (two slashes) are ignored.
Only one file or resource can be specified per directive.
Multiple references to page-based scripts are not allowed.
If a page reference is specified, no other type of reference directives is allowed.
File names use relative paths. You can use the tilde operator (~) to make application-root-relative paths.
Absolute paths are ignored.
Reference directives in referenced pages will not be processed—that is, reference directives are not resolved recursively for pages. Only script that is referenced directly by the page is included.
The dedicated worker reference group is for HTML5 Web Workers. Files specified in this group are in scope for .js files that have an explicit reference to a dedicated worker reference group. Implicit references do not apply to .js files that have an explicit reference to a dedicated worker reference group.
The IntelliSense references are typically used to provide IntelliSense support for global objects and for IntelliSense extensions. You can also use this feature for scripts that must be loaded at runtime using the script loader.
XML Documentation Comments
IntelliSense can display code references for XML comments in the following file-reference scenarios:
A .js file that references another .js file.
A .js file that references an .aspx file.
An .aspx file that references a .js file.
IntelliSense is not available when one .aspx file references another .aspx file.
ASP.NET AJAX Objects
Underlined elements in the editor. Wavy red underlines indicate errors. If you hold the mouse pointer over the error, a tooltip displays the error description.
Error List window. The Error List window displays the error description, the file where the error occurred, the line and column number, and the project. To display the Error List window, in the View menu, click Error List.
The Output window shows references that were not loaded.
Back to top