HtmlLink.Href 属性

定义

获取或设置在 HtmlLink 控件中指定的链接的 URL 目标。Gets or sets the URL target of the link specified in the HtmlLink control.

public:
 virtual property System::String ^ Href { System::String ^ get(); void set(System::String ^ value); };
public virtual string Href { get; set; }
member this.Href : string with get, set
Public Overridable Property Href As String

属性值

String

链接的 URL 目标。The URL target of the link.

示例

下面的代码示例演示如何将 Href 属性设置为级联样式表 (CSS) 与网页保存在同一目录中。The following code example demonstrates setting the Href property to a cascading style sheet (CSS) that is saved in the same directory as the Web page. 有关完整的工作代码示例,请参阅 HtmlLink 类概述主题。For a complete, working code example, see the HtmlLink class overview topic.

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

注解

Href属性指定在控件中指定的链接的 URL 目标 HtmlLinkThe Href property specifies the URL target of the link specified in the HtmlLink control. 您可以使用此属性指定 (CSS) 的外部级联样式表的位置。You can use this property to specify the location of an external cascading style sheet (CSS).

适用于