Control 类
定义由所有 ASP.NET 服务器控件共享的属性、方法和事件。
**命名空间:**System.Web.UI
**程序集:**System.Web(在 system.web.dll 中)
语法
声明
<BindableAttribute(True)> _
<ThemeableAttribute(False)> _
Public Class Control
Implements IComponent, IDisposable, IParserAccessor, IUrlResolutionService, _
IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
用法
Dim instance As Control
[BindableAttribute(true)]
[ThemeableAttribute(false)]
public class Control : IComponent, IDisposable, IParserAccessor,
IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
[BindableAttribute(true)]
[ThemeableAttribute(false)]
public ref class Control : IComponent, IDisposable, IParserAccessor,
IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor
/** @attribute BindableAttribute(true) */
/** @attribute ThemeableAttribute(false) */
public class Control implements IComponent, IDisposable,
IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor,
IExpressionsAccessor
BindableAttribute(true)
ThemeableAttribute(false)
public class Control implements IComponent, IDisposable,
IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor,
IExpressionsAccessor
备注
这是在开发自定义 ASP.NET 服务器控件时作为派生源的主要类。Control 没有任何针对用户界面 (UI) 的功能。如果创作没有 UI 的控件或者组合其他呈现它们自己的 UI 的控件,则从 Control 派生。如果创作具有 UI 的控件,则从 WebControl 或 System.Web.UI.WebControls 命名空间中的任何控件派生,该命名空间为自定义控件提供适当的起点。
Control 类是包括自定义控件、用户控件和页在内的所有 ASP.NET 服务器控件的基类。ASP.NET 页是 Page 类(该类从 Control 类继承)的实例,并且处理对扩展名为 .aspx 的文件的请求。
Control 类可以直接或间接地用作 Web 应用程序的用户界面的一部分,因此应对它进行仔细检查,以确保遵循编写安全代码和保护应用程序的最佳做法。有关这些主题的常规信息,请参见 Web 应用程序安全威胁概述、安全策略最佳实施策略 和 安全性的基础概念。有关更具体的信息,请参见 保证标准控件的安全、如何:显示安全错误信息、如何:通过对字符串应用 HTML 编码在 Web 应用程序中防止脚本侵入 和 验证控件介绍。
示例
下面的示例说明从 Control 类派生的自定义服务器控件。InnerContent
类重写 Control.Render 方法,检查此类在页上是否有子控件,并检查控件的第一个子控件是否为文本控件。如果这两个条件都符合,则被重写的方法会将 HTML 字符串 <H2>Your Message:、文本控件的内容和结束 </H2> 标记写入 Web 窗体页。
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:="Execution")> _
Protected Overrides Sub Render(output As HtmlTextWriter)
If HasControls() And TypeOf Controls(0) Is LiteralControl Then
output.Write("<H2>Your message : ")
Controls(0).RenderControl(output)
output.Write("</H2>")
End If
End Sub 'Render
End Class 'InnerContent
End Namespace 'SimpleControlSamples
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="Execution")]
protected override void Render(HtmlTextWriter output) {
if ( (HasControls()) && (Controls[0] is LiteralControl) ) {
output.Write("<H2>Your message : ");
Controls[0].RenderControl(output);
output.Write("</H2>");
}
}
}
}
package SimpleControlSamples;
import System.*;
import System.Web.*;
import System.Web.UI.*;
public class InnerContent extends Control
{
/** @attribute System.Security.Permissions.PermissionSet(
System.Security.Permissions.SecurityAction.Demand, Name = "Execution")
*/
protected void Render(HtmlTextWriter output)
{
if (HasControls() &&
get_Controls().get_Item(0) instanceof LiteralControl) {
output.Write("<H2>Your message: ");
get_Controls().get_Item(0).RenderControl(output);
output.Write("</H2>");
}
} //Render
} //InnerContent
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>");
}
}
}
}
.NET Framework 安全性
- AspNetHostingPermission 用于在宿主环境中进行操作。要求值:LinkDemand;权限值:Minimal。
- AspNetHostingPermission 用于在宿主环境中进行操作。要求值:InheritanceDemand;权限值:Minimal。
继承层次结构
System.Object
System.Web.UI.Control
派生类
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
Control 成员
System.Web.UI 命名空间
Page
TemplateControl
LiteralControl
WebControl