NonVisualControlAttribute Class
.NET Framework Class Library
NonVisualControlAttribute Class

Defines the attribute that indicates whether a control is treated as a visual or non-visual control during design time. This class cannot be inherited.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Class)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class NonVisualControlAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As NonVisualControlAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Class)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class NonVisualControlAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Class)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class NonVisualControlAttribute sealed : public Attribute
JScript
public final class NonVisualControlAttribute extends Attribute

The NonVisualControlAttribute attribute is applied to controls that are not rendered to the client, such as data source controls and the WebPartManager control. During design time, a page developer might decide to hide all non-visual controls. The designer would mark as invisible all of the controls with the NonVisualControlAttribute attribute set to true.

Examples of controls that employ the NonVisualControlAttribute attribute are DataSourceControl, HierarchicalDataSourceControl, HiddenField, and WebPartManager.

The following code example demonstrates how you can apply the NonVisualControlAttribute attribute to a class. In this example, the default NonVisualControlAttribute attribute is applied to a data source control. This is equivalent to the NonVisual field.

Visual Basic
<NonVisualControlAttribute()> _
Public Class CustomNonVisualControl
    Inherits Control

    ' Add an implementation of custom non-visual control.

End Class
C#
[NonVisualControlAttribute()]
public class CustomNonVisualControl : Control
{
    // Add an implementation of custom non-visual control.
}
System..::.Object
  System..::.Attribute
    System.Web.UI..::.NonVisualControlAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Default rectangular gray placeholder      Koen Zomers   |   Edit   |   Show History
If you're developing a custom webcontrol which doesn't have an UI to be displayed in Visual Studio's design time, like this NonVisualControlAttribute indicates, you may want to display the default gray rectangular box. You can accomplish it by doing the following:

  1. Create a new class. Name it <yourcontrolname>Designer and make it override System.Web.UI.Design.ControlDesigner. Include a reference to System.Design if not already present.
  2. In this newly created class, add an override of the public string GetDesignTimeHtml() method.
  3. In this overriden GetDesignTimeHtml method, add the following code:

    return base.CreatePlaceHolderDesignTimeHtml();

    If you want to add some custom text in the gray box, use the following line instead:

    return base.CreatePlaceHolderDesignTimeHtml("some text to display in design mode");
  4. Above your class declaration which holds the custom control you're creating, add the following attribute:

    [DesignerAttribute(typeof(<name of the class created at step #1>))]
  5. Build your project. Now when adding your custom control from the Visual Studio Toolbox in Design mode onto an ASPX form, it will display the standard gray box where your custom control is inserted!


Processing
Page view tracker