ControlIDConverter Class
Assembly: System.Web (in system.web.dll)
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.
package Samples.AspNet.JSL ;
import System.*;
import System.ComponentModel.*;
import System.Web.UI.*;
import System.Web.UI.WebControls.*;
/** @attribute DefaultProperty("ControlID")
*/
public class DebugInfoControl extends Control
{
public DebugInfoControl()
{
} //DebugInfoControl
public DebugInfoControl(String controlID)
{
set_ControlID(controlID);
} //DebugInfoControl
/** @attribute DefaultValue("")
* @attribute TypeConverter(ControlIDConverter.class)
*/
/** @property
*/
public String get_ControlID()
{
Object o = get_ViewState().get_Item("ControlID");
if (o == null) {
return "";
}
return (String)(o);
}//get_ControlID
/** @property
*/
public void set_ControlID(String value)
{
if (!(get_ControlID().Equals(value))) {
get_ViewState().set_Item("ControlID", value);
}
}//set_ControlID
protected void Render(HtmlTextWriter writer)
{
Label info = new Label();
if (this.get_ControlID().length() == 0) {
writer.Write("<Font Color='Red'>No ControlID set.</Font>");
}
Control ctrl = this.FindControl(get_ControlID());
if (ctrl == null) {
writer.Write(("<Font Color='Red'>Could not find control "
+ get_ControlID() + " in Naming Container.</Font>"));
}
else {
writer.Write(("<Font Color='Green'>Control " + get_ControlID()
+ " found.<BR>"));
writer.Write(("Its Naming Container is: " +
ctrl.get_NamingContainer().get_ID() + "<BR>"));
if (ctrl.get_EnableViewState()) {
writer.Write("It uses view state to persist its state.<BR>");
}
if (ctrl.get_EnableTheming()) {
writer.Write("It can be assigned a Theme ID.<BR>");
}
if (ctrl.get_Visible()) {
writer.Write("It is visible on the page.<BR>");
}
else {
writer.Write("It is not visible on the page.<BR>");
}
writer.Write("</Font>");
}
} //Render
} //DebugInfoControl
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.JSL" assembly="Samples.AspNet.JSL" %>
<%@Page Language="VJ#" %>
<!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>
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.ComponentModel.TypeConverter
System.ComponentModel.StringConverter
System.Web.UI.WebControls.ControlIDConverter
System.Web.UI.WebControls.AssociatedControlConverter
System.Web.UI.WebControls.ValidatedControlConverter