Export (0) Print
Expand All

ControlIDConverter Class

Provides a type converter that retrieves a list of control IDs in the current container.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

'Declaration
Public Class ControlIDConverter _
	Inherits StringConverter

The ControlIDConverter type exposes the following members.

  NameDescription
Public methodControlIDConverterInitializes a new instance of the ControlIDConverter class.
Top

  NameDescription
Public methodCanConvertFrom(Type)Returns whether this converter can convert an object of the given type to the type of this converter. (Inherited from TypeConverter.)
Public methodCanConvertFrom(ITypeDescriptorContext, Type)Gets a value indicating whether this converter can convert an object in the given source type to a string using the specified context. (Inherited from StringConverter.)
Public methodCanConvertTo(Type)Returns whether this converter can convert the object to the specified type. (Inherited from TypeConverter.)
Public methodCanConvertTo(ITypeDescriptorContext, Type)Returns whether this converter can convert the object to the specified type, using the specified context. (Inherited from TypeConverter.)
Public methodConvertFrom(Object)Converts the given value to the type of this converter. (Inherited from TypeConverter.)
Public methodConvertFrom(ITypeDescriptorContext, CultureInfo, Object)Converts the specified value object to a String object. (Inherited from StringConverter.)
Public methodConvertFromInvariantString(String)Converts the given string to the type of this converter, using the invariant culture. (Inherited from TypeConverter.)
Public methodConvertFromInvariantString(ITypeDescriptorContext, String)Converts the given string to the type of this converter, using the invariant culture and the specified context. (Inherited from TypeConverter.)
Public methodConvertFromString(String)Converts the specified text to an object. (Inherited from TypeConverter.)
Public methodConvertFromString(ITypeDescriptorContext, String)Converts the given text to an object, using the specified context. (Inherited from TypeConverter.)
Public methodConvertFromString(ITypeDescriptorContext, CultureInfo, String)Converts the given text to an object, using the specified context and culture information. (Inherited from TypeConverter.)
Public methodConvertTo(Object, Type)Converts the given value object to the specified type, using the arguments. (Inherited from TypeConverter.)
Public methodConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)Converts the given value object to the specified type, using the specified context and culture information. (Inherited from TypeConverter.)
Public methodConvertToInvariantString(Object)Converts the specified value to a culture-invariant string representation. (Inherited from TypeConverter.)
Public methodConvertToInvariantString(ITypeDescriptorContext, Object)Converts the specified value to a culture-invariant string representation, using the specified context. (Inherited from TypeConverter.)
Public methodConvertToString(Object)Converts the specified value to a string representation. (Inherited from TypeConverter.)
Public methodConvertToString(ITypeDescriptorContext, Object)Converts the given value to a string representation, using the given context. (Inherited from TypeConverter.)
Public methodConvertToString(ITypeDescriptorContext, CultureInfo, Object)Converts the given value to a string representation, using the specified context and culture information. (Inherited from TypeConverter.)
Public methodCreateInstance(IDictionary)Re-creates an Object given a set of property values for the object. (Inherited from TypeConverter.)
Public methodCreateInstance(ITypeDescriptorContext, IDictionary)Creates an instance of the type that this TypeConverter is associated with, using the specified context, given a set of property values for the object. (Inherited from TypeConverter.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFilterControlReturns a value indicating whether the control ID of the specified control is added to the TypeConverter.StandardValuesCollection that is returned by the GetStandardValues method.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected methodGetConvertFromExceptionReturns an exception to throw when a conversion cannot be performed. (Inherited from TypeConverter.)
Protected methodGetConvertToExceptionReturns an exception to throw when a conversion cannot be performed. (Inherited from TypeConverter.)
Public methodGetCreateInstanceSupportedReturns whether changing a value on this object requires a call to the CreateInstance method to create a new value. (Inherited from TypeConverter.)
Public methodGetCreateInstanceSupported(ITypeDescriptorContext)Returns whether changing a value on this object requires a call to CreateInstance to create a new value, using the specified context. (Inherited from TypeConverter.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetProperties(Object)Returns a collection of properties for the type of array specified by the value parameter. (Inherited from TypeConverter.)
Public methodGetProperties(ITypeDescriptorContext, Object)Returns a collection of properties for the type of array specified by the value parameter, using the specified context. (Inherited from TypeConverter.)
Public methodGetProperties(ITypeDescriptorContext, Object, Attribute())Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes. (Inherited from TypeConverter.)
Public methodGetPropertiesSupportedReturns whether this object supports properties. (Inherited from TypeConverter.)
Public methodGetPropertiesSupported(ITypeDescriptorContext)Returns whether this object supports properties, using the specified context. (Inherited from TypeConverter.)
Public methodGetStandardValuesReturns a collection of standard values from the default context for the data type this type converter is designed for. (Inherited from TypeConverter.)
Public methodGetStandardValues(ITypeDescriptorContext)Returns a collection of control IDs from the container within the IDesignerHost when provided with a format context. (Overrides TypeConverter.GetStandardValues(ITypeDescriptorContext).)
Public methodGetStandardValuesExclusiveReturns whether the collection of standard values returned from GetStandardValues is an exclusive list. (Inherited from TypeConverter.)
Public methodGetStandardValuesExclusive(ITypeDescriptorContext)Returns a value indicating whether the collection of standard values returned by the GetStandardValues method is an exclusive list of possible values, using the specified context. (Overrides TypeConverter.GetStandardValuesExclusive(ITypeDescriptorContext).)
Public methodGetStandardValuesSupportedReturns whether this object supports a standard set of values that can be picked from a list. (Inherited from TypeConverter.)
Public methodGetStandardValuesSupported(ITypeDescriptorContext)Returns a value indicating whether this object supports a standard set of control ID values that can be picked from a list, using the specified context. (Overrides TypeConverter.GetStandardValuesSupported(ITypeDescriptorContext).)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsValid(Object)Returns whether the given value object is valid for this type. (Inherited from TypeConverter.)
Public methodIsValid(ITypeDescriptorContext, Object)Returns whether the given value object is valid for this type and for the specified context. (Inherited from TypeConverter.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSortPropertiesSorts a collection of properties. (Inherited from TypeConverter.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The ControlIDConverter class derives from the StringConverter class and provides a list of control IDs for display in a property grid control in design-time environments. The ControlIDConverter class also serves as the base class for the AssociatedControlConverter and ValidatedControlConverter classes, which are type converters for Web controls and controls that support validation property attributes, respectively.

For more information about type converters, see How to: Implement a Type Converter or Generalized Type Conversion.

The following code example demonstrates how to use the ControlIDConverter in a class that requires a TypeConverter to render the ID of a control. The DebugInfoControl is a simple control that prints out some information on a control contained by the current Web Form. Its ControlID property is decorated with a TypeConverterAttribute that designates the ControlIDConverter as the TypeConverter to use for that property. The DebugInfoControloverrides the Render method to print out information about the target control in a Label control.

Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls

Namespace Samples.AspNet.VB

  <DefaultProperty("ControlID")>  _
  Public Class DebugInfoControl
     Inherits Control


     Public Sub New()
     End Sub 'New 


     Public Sub New(controlID As String)
        ControlID = controlID
     End Sub 'New


     <DefaultValue(""), TypeConverter(GetType(ControlIDConverter))>  _
     Public Property ControlID() As String 
        Get 
           Dim o As Object = ViewState("ControlID")
           If o Is Nothing Then 
              Return String.Empty
           End If 
           Return CStr(o)
        End Get 
        Set 
           If ControlID <> value Then
              ViewState("ControlID") = value
           End If 
        End Set 
     End Property 


     Protected Overrides Sub Render(writer As HtmlTextWriter)

        Dim info As New Label()

        If Me.ControlID.Length = 0 Then
           writer.Write("<Font Color='Red'>No ControlID set.</Font>")
        End If 

        Dim ctrl As Control = Me.FindControl(ControlID)


        If ctrl Is Nothing Then
           writer.Write(("<Font Color='Red'>Could not find control " + ControlID + " in Naming Container.</Font>"))
        Else
           writer.Write(("<Font Color='Green'>Control " + ControlID + " found.<BR>"))
           writer.Write(("Its Naming Container is: " + ctrl.NamingContainer.ID + "<BR>"))
           If ctrl.EnableViewState Then
              writer.Write("It uses view state to persist its state.<BR>")
           End If 
           If ctrl.EnableTheming Then
              writer.Write("It can be assigned a Theme ID.<BR>")
           End If 
           If ctrl.Visible Then
              writer.Write("It is visible on the page.<BR>")
           Else
              writer.Write("It is not visible on the page.<BR>")
           End If
           writer.Write("</Font>")
        End If 
     End Sub 'Render
  End Class 'DebugInfoControl
End Namespace

The following code example demonstrates how the DebugInfoControl can be used in a Web Form along with an AccessDataSource control to display information about the AccessDataSource control.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" assembly="Samples.AspNet.VB" %>
<%@ Page  Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <asp:accessdatasource
          id="AccessDataSource1"
          runat="server"
          datasourcemode="DataReader"
          datafile="Northwind.mdb"
          selectcommand="SELECT OrderID FROM Orders WHERE EmployeeID=2">
      </asp:accessdatasource>

      <br />
      <aspSample:debuginfocontrol
          id="DebugInfoControl1"
          runat="server"
          controlid="AccessDataSource1" />

    </form>
  </body>
</html>

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

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