Freigeben über


HtmlButton-Konstruktor

Initialisiert eine neue Instanz der HtmlButton-Klasse.

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

Syntax

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

Hinweise

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

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

Eigenschaft

Anfangswert

TagName

Das Zeichenfolgenliteral "button".

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie der Web Forms-Seite ein HtmlButton-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 HtmlButton control.
         Dim NewButtonControl As New HtmlButton()

         ' Set the properties of the new HtmlButton control.
         NewButtonControl.ID = "NewButtonControl"
         NewButtonControl.InnerHtml = "Click Me"

         ' Create an EventHandler delegate for the method you want to handle the event
         ' and then add it to the list of methods called when the event is raised.
         AddHandler NewButtonControl.ServerClick, AddressOf Button_Click 

         ' Add the new HtmlButton control to the Controls collection of the
         ' PlaceHolder control. 
         ControlContainer.Controls.Add(NewButtonControl)

      End Sub

      Sub Button_Click(sender As Object, e As EventArgs)

         ' Display a simple message. 
         Message.InnerHtml = "Thank you for clicking the button."

      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlButton Constructor Example </h3>

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

      <br><br>
 
      <span ID="Message"
            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 HtmlButton control.
         HtmlButton NewButtonControl = new HtmlButton();

         // Set the properties of the new HtmlButton control.
         NewButtonControl.ID = "NewButtonControl";
         NewButtonControl.InnerHtml = "Click Me";

         // Create an EventHandler delegate for the method you want to handle the event
         // and then add it to the list of methods called when the event is raised.
         NewButtonControl.ServerClick += new System.EventHandler(this.Button_Click); 

         // Add the new HtmlButton control to the Controls collection of the
         // PlaceHolder control. 
         ControlContainer.Controls.Add(NewButtonControl);

      }

      void Button_Click(Object sender, EventArgs e)
      {

         // Display a simple message. 
         Message.InnerHtml = "Thank you for clicking the button.";

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlButton Constructor Example </h3>

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

      <br><br>
 
      <span ID="Message"
            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

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

Weitere Ressourcen

HTML-Serversteuerelemente