Learn how Visual Studio implements intellisense for Web Forms
In case you don't know, Visual Studio .NET uses XSD schemas to provide
intellisense processing for the Web Forms HTML-View architecture. Some common
schemas can be found in the following directories:
C:\Program Files\Microsoft Visual Studio .NET\Common7\Packages\schemas\html
Here are the schemas that can be found here:
-
ie3_2nav3_0.xsd - This schema includes defintions for Netscape Navigator 3.0
and Internet Explorer 3.2 markup.
-
nav4_0.xsd -This schema includes definitions for Netscape Navigator 4.0 markup.
-
ie5_0.xsd -This schema, which will probably be used more than any other,
supports Internet Explorer 5.0 or later, as of now.
C:\Program Files\Microsoft Visual Studio .NET\Common7\Packages\schemas\xml
-
AddRotator.xsd - This is not an intellisense schema, but rather contains the
definitions for the Advertisements XML file used by the AdRotator control.
-
asp.xsd - This schema contains all of the defintions for all ASP.NET server
controls. Some of the attributes and elements contained are tagged with VS.NET
tags to further extend intellisense support, such as displaying a color
picker when setting a color attribute.
-
MobilePage.xsd - This schema defines a MobilePage, provided by the Mobile
Internet Toolkit.
-
MobileForm.xsd - This schema defines a MobileForm, which must be added to a
MobilePage. This schema also contains the defintions for the Mobile controls.
-
MobileUserControl.xsd - This schema contains defintions for implementing a
Mobile User Controls. Mobile controls can be added to a Mobile user control.
-
MobileHtml32Template.xsd - This schema contains the defintions for HTML
elements and attributes that are supported by Mobile Web Forms.
-
MobileChtmlTemplate.xsd - This schema contains the defintions for cHTML
elements and attributes that are supported by Mobile Web Forms.
-
tdlschema.xsd - This schema is used by Visual Studio .NET for supporting
enterprise templates. Enterprise templates are available with the Enterprise
versions of Visual Studio .NET.
-
wshmeta.xsd - This schema contains definitions for the Windows Script Host.
-
xsdschema.xsd - This schema contains the definitions for the XSD schema.
Of the schemas listed above, we will only examine one, asp.xsd, as well as
create new one for a custom ASP.NET control. For each ASP.NET server
control available, there is a corresponding <xsd:element> definition in
the schema; and for each property of a control, there is a corresponding
<xsd:attribute> element.
Note: The above statement is not entirely correct, because some complex
properties, such as collections, are also nested as elements.
Here is the schema defintion for an ASP.NET Button control:
<!-- <asp:Button> -->
<xsd:complexType name="ButtonDef" vs:noambientcontentmodel="true">
<xsd:attribute name="CommandArgument" type="xsd:string" />
<xsd:attribute name="CausesValidation" type="xsd:boolean" />
<xsd:attribute name="Text" type="xsd:string" />
<xsd:attribute name="CommandName" type="xsd:string" />
<xsd:attribute name="OnCommand" vs:omtype="event" />
<xsd:attribute name="OnClick" vs:omtype="event" />
<xsd:attribute name="Enabled" type="xsd:boolean" />
<xsd:attribute name="BorderWidth" type="ui4" />
<xsd:attribute name="BorderColor" type="xsd:string" vs:builder="color" />
<xsd:attribute name="BorderStyle" type="BorderStyle" />
<xsd:attributeGroup ref="WebControlAttributes" />
</xsd:complexType>
The <xsd:complexType> tag defines a Button type. Therefore, anywhere
through the schema document, <xsd:element> tags can be defined that are
of type ButtonDef:
<!-- valid top-level elements -->
<xsd:element name="AdRotator" type="AdRotatorDef" />
<xsd:element name="Label" type="LabelDef" />
<xsd:element name="Button" type="ButtonDef" />
All <xsd:attribute> tags correspond with the properties of a Button
control. The syntax is <xsd:attribute name="$name" type="$type"
/>, where $name represents the property name and $type represents the
property's type. Note that these types do not have to match exactly with what
the true types for the properties are. These types are simply used by schema
validation and intellisense to validate values you set. Some of the attributes
also have vs:attribute="value" markup. This
vs attribute is a tag prefix for the Visual Studio .NET
intellisense namespace,
http://schemas.microsoft.com/Visual-Studio-Intellisense. Don't try to
navigate to this link using a web browser; the norm for XML namespaces is
to use URLs, since they are almost guaranteed to be unique. During schema
processing, VS.NET searches everything that has a VS.NET namespace attribute
applied, and performs processing based on the attribute name and value. Some
common VS.NET markup is shown below:
Common VS.NET Intellisense Schema Annotations
|
Annotation
|
Used For
|
Valid Values
|
|
vs:builder
|
Specifies the builder to be used for editing a property's
value. Builders are analagous to UITypeEditors in design-mode.
|
style, url, color
|
|
vs:friendlyname
|
Specifies the display name for the schema. This name is used in
the TargetSchema property of the DOCUMENT, as well as in the Properties dialog
of HTML and ASP.NET pages.
|
(any)
|
|
vs:iscasesensitive
|
Specifies whether the tags in the ASP.NET page are
case-sensitive.
|
true, false
|
|
vs:ishtmlschema
|
Used at the root level and specifies whether the schema is an
HTML document schema.
|
true, false
|
|
vs:nonbrowseable
|
Specifies that the attribute will not appear in statement
completion in HTML View.
|
true, false
|
|
vs:readonly
|
Specifies that the attribute can not be modified in the
Properties window in HTML View.
|
true, false
|
|
vs:requireattributequotes
|
Specifies that the attribute values in the ASP.NET page must
have quotes when used in HTML View.
|
true, false
|
The MSDN documentation provides a complete set of the Visual Studio .NET schema
annotations.
A Custom Control With Intellisense Support
To implement intellisense support for a control other than one of the ASP.NET
controls or Mobile controls, you must provide your own schema for the control's
defintion. A good thing to do is to use an Intellisense Generator, such as the
one found in the Product's section of www.bluevisionsoftware.com.
But for starters, you will simply create a new XSD schema and place it in the
same directory as the asp.xsd schema. Once there, with all the defintions
necessary, you need to apply the schema to the web form onto which your control
will be placed. This is done by adding an xmlns atttribute to the <body>
element, similar to what is done on a Mobile Web Forms page to enable
intellisense support for Mobile controls. Here is the syntax:
<body xmlns:bv="urn:http://schemas.bluevisionsoftware.com/AspNet/WebControls">
The syntax above assumes that your custom controls will have a tag prefix of
bv. Then, in HTML view of the page, you can add your custom
controls, which will then be fully supported by the VS.NET Intellisense engine.
Back to Tips and Tricks