TemplateControl 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 Page 类和 UserControl 类提供一组基本功能。
public ref class TemplateControl abstract : System::Web::UI::Control, System::Web::UI::INamingContainer
public ref class TemplateControl abstract : System::Web::UI::Control, System::Web::UI::IFilterResolutionService, System::Web::UI::INamingContainer
public abstract class TemplateControl : System.Web.UI.Control, System.Web.UI.INamingContainer
public abstract class TemplateControl : System.Web.UI.Control, System.Web.UI.IFilterResolutionService, System.Web.UI.INamingContainer
type TemplateControl = class
inherit Control
interface INamingContainer
type TemplateControl = class
inherit Control
interface INamingContainer
interface IFilterResolutionService
Public MustInherit Class TemplateControl
Inherits Control
Implements INamingContainer
Public MustInherit Class TemplateControl
Inherits Control
Implements IFilterResolutionService, INamingContainer
- 继承
- 派生
- 实现
示例
下面的代码示例演示如何派生从类命名 MyControl 的 TemplateControl 控件并重写 Construct 方法。 初始化时 MyControl ,将调用重写 Construct 的方法。
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
// The custom user control class.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class MyControl : UserControl
{
// Create a Message property and accessors.
private string _message = "No message";
public string Message
{
get { return _message; }
set { _message = value; }
}
// Create an event for this user control
public event System.EventHandler myControl;
// Override the default constructor.
protected override void Construct()
{
// Specify the handler for the OnInit method.
this.myControl += new EventHandler(MyInit);
}
protected override void OnInit(EventArgs e)
{
myControl(this, e);
Response.Write("The OnInit() method is used to raise the Init event.");
}
// Use the MyInit handler to set the Message property
void MyInit(object sender, System.EventArgs e)
{
Message = "Hello World!";
}
// Render the value of the Message property
protected override void Render(HtmlTextWriter writer)
{
writer.Write("<br>Message :" + Message);
}
}
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
' The custom user control class.
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class MyControl
Inherits UserControl
' Create a Message property and accessors.
Private _message As String = Nothing
Public Property Message() As String
Get
Return _message
End Get
Set
_message = value
End Set
End Property
' Create an event for this user control
Public Event myControl As System.EventHandler
' Override the default constructor.
Protected Overrides Sub Construct()
' Specify the handler for the OnInit method.
AddHandler Me.myControl, AddressOf MyInit
End Sub
Protected Overrides Sub OnInit(ByVal e As EventArgs)
RaiseEvent myControl(Me, e)
Response.Write("The OnInit() method is used to raise the Init event.")
End Sub
' Use the MyInit handler to set the Message property
Sub MyInit(ByVal sender As Object, ByVal e As System.EventArgs)
Message = "Hello World!"
End Sub
' Render the value of the Message property
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
writer.Write(("<br>Message :" & Message))
End Sub
End Class
注解
该 TemplateControl 类是一个抽象类,它 Page 为类和类提供通用属性和 UserControl 方法。 不会直接创建该实例的新实例 TemplateControl 。
该 TemplateControl 类定义支持声明性数据绑定表达式的方法:
使用 Eval 涉及数据源的数据绑定表达式的方法,例如简单属性或表达式。
使用该方法 XPath 分析和计算 XPath 数据绑定表达式。
对 XPathSelect 包含 XPath select 语句的表达式使用数据绑定方法。 结果是实现接口的 IEnumerable 节点集合。
有关数据绑定表达式的详细信息,请参阅 Data-Binding 表达式语法 和 绑定到数据库。
构造函数
| 名称 | 说明 |
|---|---|
| TemplateControl() |
初始化 TemplateControl 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| Adapter |
获取控件的特定于浏览器的适配器。 (继承自 Control) |
| AppRelativeTemplateSourceDirectory |
获取或设置包含此控件的 Page 或 UserControl 对象的应用程序相对虚拟目录。 (继承自 Control) |
| AppRelativeVirtualPath |
获取或设置从中分析和编译控件的文件的应用程序相对虚拟目录路径。 |
| AutoHandlers |
已过时.
ASP.NET AutoHandlers NET 2.0 中已弃用该属性。 它由生成的类使用,不适合在代码中使用。 |
| BindingContainer |
获取包含此控件的数据绑定的控件。 (继承自 Control) |
| ChildControlsCreated |
获取一个值,该值指示是否已创建服务器控件的子控件。 (继承自 Control) |
| ClientID |
获取由 ASP.NET 生成的 HTML 标记的控件 ID。 (继承自 Control) |
| ClientIDMode |
获取或设置用于生成属性值的 ClientID 算法。 (继承自 Control) |
| ClientIDSeparator |
获取一个表示属性中使用的 ClientID 分隔符的字符值。 (继承自 Control) |
| Context |
HttpContext获取与当前 Web 请求的服务器控件关联的对象。 (继承自 Control) |
| Controls |
获取一个 ControlCollection 对象,该对象代表 UI 层次结构中指定服务器控件的子控件。 (继承自 Control) |
| DataItemContainer |
获取对命名容器的引用(如果命名容器实现 IDataItemContainer)。 (继承自 Control) |
| DataKeysContainer |
获取对命名容器的引用(如果命名容器实现 IDataKeysControl)。 (继承自 Control) |
| DesignMode |
获取一个值,该值指示控件是否在设计图面上使用。 (继承自 Control) |
| EnableTheming |
获取或设置一个布尔值,该值指示主题是否应用于派生自类的 TemplateControl 控件。 |
| EnableViewState |
获取或设置一个值,该值指示服务器控件是否将视图状态及其包含的任何子控件的视图状态保存到请求客户端。 (继承自 Control) |
| Events |
获取控件的事件处理程序委托的列表。 此属性为只读。 (继承自 Control) |
| HasChildViewState |
获取一个值,该值指示当前服务器控件的子控件是否具有保存的视图状态设置。 (继承自 Control) |
| ID |
获取或设置分配给服务器控件的编程标识符。 (继承自 Control) |
| IdSeparator |
获取用于分隔控件标识符的字符。 (继承自 Control) |
| IsChildControlStateCleared |
获取一个值,该值指示此控件中包含的控件是否具有控件状态。 (继承自 Control) |
| IsTrackingViewState |
获取一个值,该值指示服务器控件是否正在保存对其视图状态的更改。 (继承自 Control) |
| IsViewStateEnabled |
获取一个值,该值指示是否为此控件启用视图状态。 (继承自 Control) |
| LoadViewStateByID |
获取一个值,该值指示控件是否参与加载其视图状态,而不是 ID 索引。 (继承自 Control) |
| NamingContainer |
获取对服务器控件命名容器的引用,该容器创建唯一的命名空间,用于区分具有相同 ID 属性值的服务器控件。 (继承自 Control) |
| Page |
获取对 Page 包含服务器控件的实例的引用。 (继承自 Control) |
| Parent |
获取对页面控件层次结构中服务器控件的父控件的引用。 (继承自 Control) |
| RenderingCompatibility |
获取一个值,该值指定呈现的 HTML 将与 ASP.NET 版本兼容。 (继承自 Control) |
| Site |
获取有关在设计图面上呈现时承载当前控件的容器的信息。 (继承自 Control) |
| SkinID |
获取或设置要应用于控件的皮肤。 (继承自 Control) |
| SupportAutoEvents |
获取一个值,该值指示控件是否 TemplateControl 支持自动事件。 |
| TemplateControl |
获取或设置对包含此控件的模板的引用。 (继承自 Control) |
| TemplateSourceDirectory |
获取包含当前服务器控件的 Page 虚拟 UserControl 目录。 (继承自 Control) |
| UniqueID |
获取服务器控件的唯一分层限定标识符。 (继承自 Control) |
| ValidateRequestMode |
获取或设置一个值,该值指示控件是否检查浏览器的客户端输入是否存在潜在危险值。 (继承自 Control) |
| ViewState |
获取状态信息的字典,该字典允许跨同一页的多个请求保存和还原服务器控件的视图状态。 (继承自 Control) |
| ViewStateIgnoresCase |
获取一个值,该值指示对象是否 StateBag 不区分大小写。 (继承自 Control) |
| ViewStateMode |
获取或设置此控件的视图状态模式。 (继承自 Control) |
| Visible |
获取或设置一个值,该值指示服务器控件是否呈现为页面上的 UI。 (继承自 Control) |
方法
活动
| 名称 | 说明 |
|---|---|
| AbortTransaction |
当用户结束事务时发生。 |
| CommitTransaction |
事务完成时发生。 |
| DataBinding |
当服务器控件绑定到数据源时发生。 (继承自 Control) |
| Disposed |
在从内存中释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生命周期的最后阶段。 (继承自 Control) |
| Error |
引发未经处理的异常时发生。 |
| Init |
在初始化服务器控件时发生,这是其生命周期中的第一步。 (继承自 Control) |
| Load |
在将服务器控件加载到对象中 Page 时发生。 (继承自 Control) |
| PreRender |
在 Control 加载对象但在呈现之前发生。 (继承自 Control) |
| Unload |
从内存中卸载服务器控件时发生。 (继承自 Control) |
显式接口实现
扩展方法
| 名称 | 说明 |
|---|---|
| EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>) |
为指定的数据控件启用动态数据行为。 |
| EnableDynamicData(INamingContainer, Type, Object) |
为指定的数据控件启用动态数据行为。 |
| EnableDynamicData(INamingContainer, Type) |
为指定的数据控件启用动态数据行为。 |
| FindDataSourceControl(Control) |
返回与指定控件的数据控件关联的数据源。 |
| FindFieldTemplate(Control, String) |
返回指定控件命名容器中指定列的字段模板。 |
| FindMetaTable(Control) |
返回包含数据控件的元表对象。 |
| GetDefaultValues(INamingContainer) |
获取指定数据控件的默认值的集合。 |
| GetMetaTable(INamingContainer) |
获取指定数据控件的表元数据。 |
| SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>) |
设置指定数据控件的表元数据和默认值映射。 |
| SetMetaTable(INamingContainer, MetaTable, Object) |
设置指定数据控件的表元数据和默认值映射。 |
| SetMetaTable(INamingContainer, MetaTable) |
设置指定数据控件的表元数据。 |
| TryGetMetaTable(INamingContainer, MetaTable) |
确定表元数据是否可用。 |