Uredi

Deli z drugimi prek


HtmlLink.Href Property

Definition

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

Property Value

The URL target of the link.

Examples

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. 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

Remarks

The Href property specifies the URL target of the link specified in the HtmlLink control. You can use this property to specify the location of an external cascading style sheet (CSS).

Applies to