Freigeben über


HtmlAnchor-Konstruktor

Initialisiert eine neue Instanz der HtmlAnchor-Klasse.

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

Syntax

'Declaration
Public Sub New
'Usage
Dim instance As New HtmlAnchor
public HtmlAnchor ()
public:
HtmlAnchor ()
public HtmlAnchor ()
public function HtmlAnchor ()

Hinweise

Mit diesem Konstruktor können Sie eine neue Instanz des HtmlAnchor-Steuerelements erstellen und initialisieren.

In der folgenden Tabelle ist der anfängliche Eigenschaftenwert für eine Instanz von HtmlAnchor aufgeführt.

Eigenschaft

Anfangswert

TagName

Das Zeichenfolgenliteral "a".

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie der Web Forms-Seite ein HtmlAnchor-Steuerelement dynamisch hinzugefügt wird.

<%@ Page Language="VB" AutoEventWireup="True" %>

<html> 

<head>

   <script runat="server">

      Sub Page_Load(sender As Object, e As EventArgs)
         
         ' Create a new HtmlAnchor control.
         Dim NewAnchorControl As New HtmlAnchor()

         ' Set the properties of the new HtmlAnchor control.
         NewAnchorControl.Name = "NewAnchorControl"
         NewAnchorControl.HRef = "https://www.microsoft.com"
         NewAnchorControl.Target = "_blank"
         NewAnchorControl.InnerHtml = "Microsoft Home"

         ' Add the new HtmlAnchor control to the Controls collection of the
         ' PlaceHolder control. 
         ControlContainer.Controls.Add(NewAnchorControl)

      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlAnchor Constructor Example </h3>

      <asp:PlaceHolder ID="ControlContainer"
           runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>

<html> 

<head>

   <script runat="server">

      void Page_Load(Object sender, EventArgs e)
      {
         
         // Create a new HtmlAnchor control.
         HtmlAnchor NewAnchorControl = new HtmlAnchor();

         // Set the properties of the new HtmlAnchor control.
         NewAnchorControl.Name = "NewAnchorControl";
         NewAnchorControl.HRef = "https://www.microsoft.com";
         NewAnchorControl.Target = "_blank";
         NewAnchorControl.InnerHtml = "Microsoft Home";

         // Add the new HtmlAnchor control to the Controls collection of the
         // PlaceHolder control. 
         ControlContainer.Controls.Add(NewAnchorControl);

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlAnchor Constructor Example </h3>

      <asp:PlaceHolder ID="ControlContainer"
           runat="server"/>

   </form>

</body>
</html>

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

HtmlAnchor-Klasse
HtmlAnchor-Member
System.Web.UI.HtmlControls-Namespace

Weitere Ressourcen

HTML-Serversteuerelemente