hanbing768
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
      • Microsoft Visual Studio 2005/.NET Framework 2.0
        • .NET Framework 3.0
                                                      • .NET Framework Class Library
                                                        HtmlLink Class

                                                        Allows programmatic access to the HTML link element on the server.

                                                        Namespace:System.Web.UI.HtmlControls
                                                        Assembly: 聽System.Web (in System.Web.dll)

                                                        Visual Basic (Declaration)
                                                        <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
                                                                                                                                                                    <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
                                                                                                                                                                    Public Class HtmlLink _
                                                                                                                                                                    Inherits HtmlControl
                                                                                                                                                                    
                                                        Visual Basic (Usage)
                                                        Dim instance As HtmlLink
                                                                                                                                                                    
                                                        C#
                                                        [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
                                                                                                                                                                    [AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
                                                                                                                                                                    public class HtmlLink : HtmlControl
                                                                                                                                                                    
                                                        Visual C++
                                                        [AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
                                                                                                                                                                    [AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
                                                                                                                                                                    public ref class HtmlLink : public HtmlControl
                                                                                                                                                                    
                                                        J#
                                                        /** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
                                                                                                                                                                    /** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
                                                                                                                                                                    public class HtmlLink extends HtmlControl
                                                                                                                                                                    
                                                        JScript
                                                        public class HtmlLink extends HtmlControl
                                                                                                                                                                    
                                                        ASP.NET
                                                        <asp:HtmlLink />
                                                                                                                                                                    

                                                        The HtmlLink control allows programmatic access to the HTML link element on the server. The HtmlLink control can be used to programmatically specify a cascading style sheet (CSS) reference in a Web page.

                                                        Topic Location
                                                        How to: Add HTML Server Controls to a Web Page Using ASP.NET Syntax Building ASP .NET Web Applications
                                                        How to: Add HTML Server Controls to a Web Page Using ASP.NET Syntax Building ASP .NET Web Applications
                                                        How to: Add HTML Server Controls to a Web Page Using ASP.NET Syntax Building ASP .NET Web Applications in Visual Studio
                                                        How to: Set HTML Server Control Properties Programmatically Building ASP .NET Web Applications
                                                        How to: Set HTML Server Control Properties Programmatically Building ASP .NET Web Applications
                                                        How to: Set HTML Server Control Properties Programmatically Building ASP .NET Web Applications in Visual Studio

                                                        The following code example demonstrates using the HtmlLink control to programmatically add a style sheet to a Web page.

                                                        Visual Basic
                                                        <%@ 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)
                                                                                                                                                                    \' Define an HtmlLink control.
                                                                                                                                                                    Dim myHtmlLink As New HtmlLink()
                                                                                                                                                                    myHtmlLink.Href = "~/StyleSheet.css"
                                                                                                                                                                    myHtmlLink.Attributes.Add("rel", "stylesheet")
                                                                                                                                                                    myHtmlLink.Attributes.Add("type", "text/css")
                                                                                                                                                                    \' Add the HtmlLink to the Head section of the page.
                                                                                                                                                                    Page.Header.Controls.Add(myHtmlLink)
                                                                                                                                                                    End Sub
                                                                                                                                                                    </script>
                                                                                                                                                                    <html  >
                                                                                                                                                                    <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="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)
                                                                                                                                                                    {
                                                                                                                                                                    // Define an HtmlLink control.
                                                                                                                                                                    HtmlLink myHtmlLink = new HtmlLink();
                                                                                                                                                                    myHtmlLink.Href = "~/StyleSheet.css";
                                                                                                                                                                    myHtmlLink.Attributes.Add("rel", "stylesheet");
                                                                                                                                                                    myHtmlLink.Attributes.Add("type", "text/css");
                                                                                                                                                                    // Add the HtmlLink to the Head section of the page.
                                                                                                                                                                    Page.Header.Controls.Add(myHtmlLink);
                                                                                                                                                                    }
                                                                                                                                                                    </script>
                                                                                                                                                                    <html  >
                                                                                                                                                                    <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>
                                                                                                                                                                    

                                                        To run the preceding code example, you need a cascading style sheet (CSS) named Stylesheet.css, containing the following code, saved in the same directory as your Web site.

                                                        Visual Basic
                                                        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 }
                                                                                                                                                                    
                                                        System..::.Object
                                                        聽聽System.Web.UI..::.Control
                                                        聽聽聽聽System.Web.UI.HtmlControls..::.HtmlControl
                                                        聽聽聽聽聽聽System.Web.UI.HtmlControls..::.HtmlLink
                                                        Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

                                                        Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

                                                         

                                                        The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

                                                        .NET Framework

                                                        Supported in: 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0

                                                        分类:

                                                        技术点:

                                                        相关文章: