Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
WebControl Class
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
WebControl Class

Serves as the base class that defines the methods, properties and events common to all controls in the System.Web.UI.WebControls namespace.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
<ThemeableAttribute(True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class WebControl _
    Inherits Control _
    Implements IAttributeAccessor
Visual Basic (Usage)
Dim instance As WebControl
C#
[ThemeableAttribute(true)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class WebControl : Control, IAttributeAccessor
Visual C++
[ThemeableAttribute(true)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class WebControl : public Control, 
    IAttributeAccessor
JScript
public class WebControl extends Control implements IAttributeAccessor
ASP.NET
<asp:WebControl />

The WebControl class provides the properties, methods, and events that are common to all Web server controls. You can control the appearance and behavior of a Web server control by setting properties defined in this class. For example, the background color and font color of a control are controlled by using the BackColor and ForeColor properties, respectively. On controls that can display a border, you can control the border width, the border style, and the border color by setting the BorderWidth, BorderStyle, and BorderColor properties. The size of a Web server control can be specified by using the Height and Width properties.

The behavior of the control can be specified by setting certain properties. You can enable and disable a control by setting the Enabled property. The place of the control in the tab order is controlled by setting the TabIndex property. You can specify a ToolTip for the control by setting the ToolTip property.

NoteNote:

Not all controls support every property defined in this class. For specific information about whether a property is supported, see the documentation for the specific control.

NoteNote:

Some properties in this class render differently, depending on the browser. Some properties do not render at all, while others render, but have no effect. The TagWriter property of the HttpBrowserCapabilities object determines the way in which a Web server control renders. For browsers that support HTML 4.0, the TagWriter property will contain a regular HttpBrowserCapabilities object, and most properties will be rendered using HTML 4.0 style attributes. Browsers that are not known to support HTML 4.0 will use the Html32TextWriter object. This will automatically map the style attributes to any relevant HTML 3.2 tag attributes. In some cases, such as with the ForeColor property, the style attributes will be converted into additional tags, such as <font> tags. In some cases, there will be no mapping performed. For specific information about how a property is rendered in different browsers, see the documentation for the specific property.

For a list of initial property values for an instance of WebControl, see the WebControl constructor.

TopicLocation
Developing Custom Data-Bound Controls for ASP.NET 1.1Authoring ASP.NET Controls
Developing Custom Data-Bound Controls for ASP.NET 1.1Authoring ASP.NET Controls
Developing Custom Data-Bound Controls for ASP.NET 1.1Building ASP .NET Web Applications in Visual Studio
Developing Custom Data-Bound Controls for ASP.NET 1.1Building ASP .NET Web Applications in Visual Studio
How to: Set ASP.NET Server Control Style Properties Using ASP.NET SyntaxBuilding ASP .NET Web Applications
How to: Set ASP.NET Server Control Style Properties Using ASP.NET SyntaxBuilding ASP .NET Web Applications
How to: Set ASP.NET Server Control Style Properties Using ASP.NET SyntaxBuilding ASP .NET Web Applications in Visual Studio
How to: Set ASP.NET Server Control Style Properties Using ASP.NET SyntaxBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Basic Control Designer for a Web Server ControlAuthoring ASP.NET Controls
Walkthrough: Creating a Basic Control Designer for a Web Server ControlAuthoring ASP.NET Controls
Walkthrough: Creating a Basic Control Designer for a Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Basic Control Designer for a Web Server ControlBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Custom Data-Bound ASP.NET Web Control for ASP.NET 1.1Authoring ASP.NET Controls
Walkthrough: Creating a Custom Data-Bound ASP.NET Web Control for ASP.NET 1.1Authoring ASP.NET Controls
Walkthrough: Creating a Custom Data-Bound ASP.NET Web Control for ASP.NET 1.1Building ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Custom Data-Bound ASP.NET Web Control for ASP.NET 1.1Building ASP .NET Web Applications in Visual Studio
Walkthrough: Developing and Using a Custom Server ControlAuthoring ASP.NET Controls
Walkthrough: Developing and Using a Custom Server ControlAuthoring ASP.NET Controls
Walkthrough: Developing and Using a Custom Server ControlBuilding Applications with Visual Web Developer
Walkthrough: Developing and Using a Custom Server ControlBuilding ASP .NET Web Applications in Visual Studio
Visual Basic
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace ControlTest

   ' Renders the following HTML: 
   ' <span onclick="alert('Hello');" style="color:Red;">Custom Contents</span>
   Public Class MyWebControl
      Inherits WebControl


      Public Sub New()
         MyBase.New(HtmlTextWriterTag.Span)
      End Sub 'New      

      <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
      Protected Overrides Sub AddAttributesToRender(writer As HtmlTextWriter)

         writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');")
         writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red")
         MyBase.AddAttributesToRender(writer)

      End Sub 'AddAttributesToRender       

      <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
      Protected Overrides Sub RenderContents(writer As HtmlTextWriter)
         writer.Write("Custom Contents")
         MyBase.RenderContents(writer)
      End Sub 'RenderContents

   End Class 'MyWebControl

End Namespace 'ControlTest

C#
namespace ControlTest 
{
   using System;
   using System.Web.UI;
   using System.Web.UI.WebControls;

   // Renders the following HTML: 
   // <span onclick="alert('Hello');" style="color:Red;">Custom Contents</span>

   public class MyWebControl: WebControl {

      public MyWebControl() : base(HtmlTextWriterTag.Span) 
      { }

      [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
      protected override void AddAttributesToRender(HtmlTextWriter writer) 
      {

         writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "alert('Hello');");
         writer.AddStyleAttribute(HtmlTextWriterStyle.Color, "Red");
         base.AddAttributesToRender(writer);

      }

      [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
      protected override void RenderContents(HtmlTextWriter writer) 
      {
         writer.Write("Custom Contents");
         base.RenderContents(writer);
      }
   }
}

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, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker