HtmlLink 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
允许以编程方式访问服务器上的 HTML link 元素。
public ref class HtmlLink : System::Web::UI::HtmlControls::HtmlControl
public class HtmlLink : System.Web.UI.HtmlControls.HtmlControl
type HtmlLink = class
inherit HtmlControl
Public Class HtmlLink
Inherits HtmlControl
- 继承
示例
下面的代码示例演示如何使用 HtmlLink 控件以编程方式向网页添加样式表。
<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Init(object sender, EventArgs e)
{
// <snippet2>
// Define an HtmlLink control.
HtmlLink myHtmlLink = new HtmlLink();
myHtmlLink.Href = "~/StyleSheet.css";
myHtmlLink.Attributes.Add("rel", "stylesheet");
myHtmlLink.Attributes.Add("type", "text/css");
// </snippet2>
// Add the HtmlLink to the Head section of the page.
Page.Header.Controls.Add(myHtmlLink);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1"
runat="server">
<title>HtmlLink Example Page</title>
</head>
<body>
<form id="form1"
runat="server">
<h1>HtmlLink Example Page</h1>
This is some text in the body of the Web Forms page.
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
' <snippet2>
' Define an HtmlLink control.
Dim myHtmlLink As New HtmlLink()
myHtmlLink.Href = "~/StyleSheet.css"
myHtmlLink.Attributes.Add("rel", "stylesheet")
myHtmlLink.Attributes.Add("type", "text/css")
' </snippet2>
' Add the HtmlLink to the Head section of the page.
Page.Header.Controls.Add(myHtmlLink)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1"
runat="server">
<title>HtmlLink Example Page</title>
</head>
<body>
<form id="form1"
runat="server">
<h1>HtmlLink Example Page</h1>
This is some text in the body of the Web Forms page.
</form>
</body>
</html>
若要运行前面的代码示例,需要一个名为 Stylesheet.css级联样式表(CSS),其中包含以下代码,保存在网站所在的同一目录中。
body {
padding-left: 11em;
font-family: Verdana, "Times New Roman",
Times, serif;
color: blue;
background-color: silver }
h1 {
font-family: Helvetica, Geneva, Arial,
SunSans-Regular, sans-serif;
color: purple }
body {
padding-left: 11em;
font-family: Verdana, "Times New Roman",
Times, serif;
color: blue;
background-color: silver }
h1 {
font-family: Helvetica, Geneva, Arial,
SunSans-Regular, sans-serif;
color: purple }
注解
该 HtmlLink 控件允许以编程方式访问服务器上的 HTML link 元素。 该 HtmlLink 控件可用于以编程方式在网页中指定级联样式表(CSS)引用。
构造函数
| 名称 | 说明 |
|---|---|
| HtmlLink() |
初始化 HtmlLink 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| Adapter |
获取控件的特定于浏览器的适配器。 (继承自 Control) |
| AppRelativeTemplateSourceDirectory |
获取或设置包含此控件的 Page 或 UserControl 对象的应用程序相对虚拟目录。 (继承自 Control) |
| Attributes |
获取在 ASP.NET 页中的服务器控件标记上表示的所有属性名称和值对的集合。 (继承自 HtmlControl) |
| 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) |
| Disabled |
获取或设置一个值,该值指示是否禁用 HTML 服务器控件。 (继承自 HtmlControl) |
| EnableTheming |
获取或设置一个值,该值指示主题是否应用于此控件。 (继承自 Control) |
| EnableViewState |
获取或设置一个值,该值指示服务器控件是否将视图状态及其包含的任何子控件的视图状态保存到请求客户端。 (继承自 Control) |
| Events |
获取控件的事件处理程序委托的列表。 此属性为只读。 (继承自 Control) |
| HasChildViewState |
获取一个值,该值指示当前服务器控件的子控件是否具有保存的视图状态设置。 (继承自 Control) |
| Href |
获取或设置控件中指定的 HtmlLink 链接的 URL 目标。 |
| 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) |
| Style |
获取应用于 ASP.NET 文件中指定 HTML 服务器控件的所有级联样式表(CSS)属性的集合。 (继承自 HtmlControl) |
| TagName |
获取包含 |
| TemplateControl |
获取或设置对包含此控件的模板的引用。 (继承自 Control) |
| TemplateSourceDirectory |
获取包含当前服务器控件的 Page 虚拟 UserControl 目录。 (继承自 Control) |
| UniqueID |
获取服务器控件的唯一分层限定标识符。 (继承自 Control) |
| ValidateRequestMode |
获取或设置一个值,该值指示控件是否检查浏览器的客户端输入是否存在潜在危险值。 (继承自 Control) |
| ViewState |
获取状态信息的字典,该字典允许跨同一页的多个请求保存和还原服务器控件的视图状态。 (继承自 Control) |
| ViewStateIgnoresCase |
获取一个值,该值指示视图状态是否 HtmlControl 区分大小写。 (继承自 HtmlControl) |
| ViewStateMode |
获取或设置此控件的视图状态模式。 (继承自 Control) |
| Visible |
获取或设置一个值,该值指示服务器控件是否呈现为页面上的 UI。 (继承自 Control) |
方法
活动
| 名称 | 说明 |
|---|---|
| DataBinding |
当服务器控件绑定到数据源时发生。 (继承自 Control) |
| Disposed |
在从内存中释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生命周期的最后阶段。 (继承自 Control) |
| Init |
在初始化服务器控件时发生,这是其生命周期中的第一步。 (继承自 Control) |
| Load |
在将服务器控件加载到对象中 Page 时发生。 (继承自 Control) |
| PreRender |
在 Control 加载对象但在呈现之前发生。 (继承自 Control) |
| Unload |
从内存中卸载服务器控件时发生。 (继承自 Control) |
显式接口实现
扩展方法
| 名称 | 说明 |
|---|---|
| FindDataSourceControl(Control) |
返回与指定控件的数据控件关联的数据源。 |
| FindFieldTemplate(Control, String) |
返回指定控件命名容器中指定列的字段模板。 |
| FindMetaTable(Control) |
返回包含数据控件的元表对象。 |