ControlIDConverter (Clase)
Ensamblado: System.Web (en system.web.dll)
La clase ControlIDConverter se deriva de la clase StringConverter y proporciona una lista de id. de control para su presentación en un control de cuadrícula de propiedades en entornos en tiempo de diseño. La clase ControlIDConverter también actúa como clase base para las clases AssociatedControlConverter y ValidatedControlConverter, que son los convertidores de tipos para los controles Web y los controles que admiten atributos de propiedades de validación, respectivamente.
Para obtener más información sobre los convertidores de tipos, vea Cómo: Implementar un convertidor de tipos o Conversión de tipos generalizada.
En el ejemplo de código siguiente se muestra cómo utilizar ControlIDConverter en una clase que exige a TypeConverter que represente el id. de un control. DebugInfoControl es un control sencillo que imprime alguna información sobre un control contenido en el formulario Web Forms actual. Su propiedad ControlID está decorada con un atributo TypeConverterAttribute que designa ControlIDConverter como TypeConverter que se utilizará para esa propiedad. DebugInfoControl reemplaza el método Render para imprimir información sobre el control de destino en un control Label.
namespace Samples.AspNet.CS { using System; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; [DefaultProperty("ControlID")] public class DebugInfoControl : Control { public DebugInfoControl() { } public DebugInfoControl(string controlID) { ControlID = controlID; } [DefaultValue(""), TypeConverter(typeof(ControlIDConverter))] public string ControlID { get { object o = ViewState["ControlID"]; if (o == null) return String.Empty; return (string)o; } set { if (ControlID != value) { ViewState["ControlID"] = value; } } } protected override void Render(HtmlTextWriter writer) { Label info = new Label(); if (this.ControlID.Length == 0) { writer.Write("<Font Color='Red'>No ControlID set.</Font>"); } Control ctrl = this.FindControl(ControlID); if (ctrl == null) { 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) writer.Write("It uses view state to persist its state.<BR>"); if (ctrl.EnableTheming) writer.Write("It can be assigned a Theme ID.<BR>"); if (ctrl.Visible) writer.Write("It is visible on the page.<BR>"); else writer.Write("It is not visible on the page.<BR>"); writer.Write("</Font>"); } } } }
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
El ejemplo de código siguiente muestra cómo DebugInfoControl se puede utilizar en un formulario Web Forms junto con un control AccessDataSource para mostrar información sobre el control AccessDataSource.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" assembly="Samples.AspNet.CS" %> <%@Page Language="C#" %> <!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>
<%@ 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 para trabajar en un entorno alojado en host. Valor de la petición: LinkDemand; valor del permiso: Minimal
- AspNetHostingPermission para trabajar en un entorno alojado en host. Valor de la petición: InheritanceDemand; valor del permiso: Minimal
System.ComponentModel.TypeConverter
System.ComponentModel.StringConverter
System.Web.UI.WebControls.ControlIDConverter
System.Web.UI.WebControls.AssociatedControlConverter
System.Web.UI.WebControls.ValidatedControlConverter
Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter
Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.