HtmlLink 构造函数

定义

初始化 HtmlLink 类的新实例。

public:
 HtmlLink();
public HtmlLink ();
Public Sub New ()

示例

下面的代码示例演示如何以编程方式声明 HtmlLink 控件并定义其属性。 有关完整的工作代码示例,请参阅 HtmlLink 类概述主题。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class HtmlLinkcs_aspx
{
    void Page_Init(object sender, EventArgs e)
    {
        // Create an instance of HtmlLink.
        HtmlLink myHtmlLink = new HtmlLink();
        myHtmlLink.Href = "StyleSheet.css";     
        myHtmlLink.Attributes.Add("rel", "stylesheet");
        myHtmlLink.Attributes.Add("type", "text/css");   

        // Add the instance of HtmlLink to the <HEAD> section of the page.
        head1.Controls.Add(myHtmlLink);
    }
}
// Define an HtmlLink control.
HtmlLink myHtmlLink = new HtmlLink();
myHtmlLink.Href = "~/StyleSheet.css";
myHtmlLink.Attributes.Add("rel", "stylesheet");
myHtmlLink.Attributes.Add("type", "text/css");
' Define an HtmlLink control.
Dim myHtmlLink As New HtmlLink()
myHtmlLink.Href = "~/StyleSheet.css"
myHtmlLink.Attributes.Add("rel", "stylesheet")
myHtmlLink.Attributes.Add("type", "text/css")
Partial Class HtmlLinkvb_aspx

    Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)

        ' Create an instance of HtmlLink.
        Dim myHtmlLink As HtmlLink = New HtmlLink()
        myHtmlLink.Href = "StyleSheet.css"
        myHtmlLink.Attributes.Add("rel", "stylesheet")
        myHtmlLink.Attributes.Add("type", "text/css")

        ' Add the instance of HtmlLink to the <HEAD> section of the page.
        head1.Controls.Add(myHtmlLink)

    End Sub

End Class

注解

使用此构造函数创建和初始化控件的新实例 HtmlLink

适用于