Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Control Class

Defines the properties, methods, and events that are shared by all ASP.NET server controls.

For a list of all members of this type, see Control Members.

System.Object
   System.Web.UI.Control
      Derived classes

[Visual Basic]
Public Class Control
   Implements IComponent, IDisposable, IParserAccessor, _
   IDataBindingsAccessor
[C#]
public class Control : IComponent, IDisposable, IParserAccessor,
   IDataBindingsAccessor
[C++]
public __gc class Control : public IComponent, IDisposable,
   IParserAccessor, IDataBindingsAccessor
[JScript]
public class Control implements IComponent, IDisposable,
   IParserAccessor, IDataBindingsAccessor

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

This is the primary class that you derive from when you develop custom ASP.NET server controls. Control does not have any user interface (UI) specific features. If you are authoring a control that does not have a UI, or combines other controls that render their own UI, derive from Control.

ASP.NET server controls include ASP.NET pages. Pages are instantiations classes derived from the Page class when a request for an ASP.NET page is processed. Also included are literal controls (strings of HTML and text that are not processed on the server), HTML server controls, Web server controls, and any custom server controls that you create or download.

Example

The following example demonstrates a custom server control that derives from the Control class. The InnerContent class overrides the Control.Render method, checks to see if the class has any child controls on the page and determines whether the first child of the control is a literal control. If both of these conditions are met, the overridden method writes the HTML string <H2>Your Message:, the contents of the literal control, and a closing </H2> tag to the Web Forms page.

[Visual Basic] 
Option Explicit
Option Strict

Imports System
Imports System.Web
Imports System.Web.UI
Imports Microsoft.VisualBasic

Namespace SimpleControlSamples
    Public Class InnerContent
        Inherits Control
        <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
        Protected Overrides Sub Render(output As HtmlTextWriter)
            
            If HasControls() And TypeOf Controls(0) Is LiteralControl Then
                output.Write("<H2>Your Message: " & CType(Controls(0), LiteralControl).Text & "</H2>")                
            End If
        End Sub 'Render
    End Class 'InnerContent
End Namespace 'SimpleControlSamples

[C#] 
using System;
using System.Web;
using System.Web.UI;

namespace SimpleControlSamples {

    public class InnerContent : Control {
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
       protected override void Render(HtmlTextWriter output) {

           if ( (HasControls()) && (Controls[0] is LiteralControl) ) {
              output.Write("<H2>Your Message: " + ((LiteralControl) Controls[0]).Text + "</H2>");
           }
       }
    }    
}
   

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Web.dll>
using namespace System;
using namespace System::Web;
using namespace System::Web::UI;

public __gc class InnerContent : public Control {
protected:
   [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name=S"FullTrust")] 
   void Render(HtmlTextWriter* output) {

      if ( (HasControls()) && dynamic_cast<LiteralControl*>(Controls->Item[0]) ) {
         output->Write(S"<H2>Your Message: {0}</H2>", (dynamic_cast<LiteralControl*>(Controls->Item[0]))->Text);
      }
   }
};    

[JScript] 
import System;
import System.Web;
import System.Web.UI;
import System.Security.Permissions;

package SimpleControlSamples {

    public class InnerContent extends Control {

       protected override function Render(output : HtmlTextWriter) {
    var securityperm : SecurityPermission;
         securityperm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
         securityperm.Demand();
           if ( (HasControls()) && (typeof(Controls[0]) == LiteralControl) ) {
              output.Write("<H2>Your Message: " + (LiteralControl(Controls[0])).Text + "</H2>");
           }
       }
    }    
}
   

Requirements

Namespace: System.Web.UI

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web (in System.Web.dll)

See Also

Control Members | System.Web.UI Namespace | Developing ASP.NET Server Controls | Page | TemplateControl | LiteralControl

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft