Freigeben über


HtmlForm-Konstruktor

Initialisiert eine neue Instanz der HtmlForm-Klasse.

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

Syntax

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

Hinweise

Mit diesem Konstruktor können Sie eine neue Instanz der HtmlForm-Klasse erstellen und initialisieren.

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

Eigenschaft

Anfangswert

TagName

Das Zeichenfolgenliteral "form".

Beispiel

Im folgenden Codebeispiel wird das Erstellen einer neuen Instanz des HtmlForm-Steuerelements und das Platzieren auf der Webseite veranschaulicht.

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

<script runat="server" >
  
  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
         
    ' Create a new HtmlForm control.
    Dim form As HtmlForm = New HtmlForm()
    form.ID = "ButtonForm"

    ' Create an HtmlButton control.
    Dim button As HtmlButton = New HtmlButton()
    button.InnerHtml = "Click Me"

    ' Register the event-handling method for the ServerClick event of the 
    ' HtmlButton control.
    AddHandler button.ServerClick, AddressOf Button_Click

    ' Add the HtmlButton control to the HtmlForm control.
    form.Controls.Add(button)

    ' Add the HtmlForm to the control collection of the page.
    Page.Controls.Add(form)
            
  End Sub

  Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
        
    ' Write a message to the user.
    Message.InnerHtml = "Hello World"

  End Sub
  
</script>

<html>

<head>

  <title>HtmlForm Constructor Example</title>

</head>
  
<body>
  
   <h3> HtmlForm Constructor Example </h3>

   <span id=Message runat="server"/> 

</body>

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

<script runat="server" >
  
  void Page_Load(Object sender, EventArgs e)
  {

    // Create a new HtmlForm control.
    HtmlForm form = new HtmlForm();
    form.ID = "ButtonForm";

    // Create an HtmlButton control.
    HtmlButton button = new HtmlButton();
    button.InnerHtml = "Click Me";

    // Register the event-handling method for the ServerClick event of the 
    // HtmlButton control.
    button.ServerClick += new System.EventHandler(this.Button_Click);

    // Add the HtmlButton control to the HtmlForm control.
    form.Controls.Add(button);

    // Add the HtmlForm control to the control collection of the page.
    Page.Controls.Add(form);

  }

  void Button_Click(Object sender, EventArgs e)
  {

    // Write a message to the user.
    Message.InnerHtml = "Hello World";

  }
  
</script>

<html>

<head>

   <title>HtmlForm Constructor Example</title>

</head>

<body>
  
   <h3> HtmlForm Constructor Example </h3>

   <span id=Message runat="server"/> 

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

HtmlForm-Klasse
HtmlForm-Member
System.Web.UI.HtmlControls-Namespace
HtmlControl.TagName-Eigenschaft

Weitere Ressourcen

HTML-Serversteuerelemente