WebControl Constructor (HtmlTextWriterTag)

Initializes a new instance of the WebControl class using the specified HTML tag.

  [Visual Basic]
  Public Sub New( _
   ByVal 
  tag
   As HtmlTextWriterTag _
)
[C#]
public WebControl(
   HtmlTextWriterTag tag
);
[C++]
public: WebControl(
   HtmlTextWriterTag tag
);
[JScript]
public function WebControl(
   tag : HtmlTextWriterTag);

Parameters

Remarks

Use this constructor to create and initialize a new instance of the WebControl class using the specified System.Web.UI.HtmlTextWriterTag value.

The following table shows the initial property value for an instance of WebControl.

Property Initial Value
TagKey The System.Web.UI.HtmlTextWriterTag enumeration value specified by the tag parameter.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the constructor for the WebControl class to create a TextArea HTML element and display it on the Web Forms page.

  [Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
 
<head>
 
   <script runat="server">
 
      Sub Button1_Click(sender As Object, e As EventArgs) 
      
         Dim wc As New WebControl(HtmlTextWriterTag.Textarea)
         PlaceHolder1.Controls.Add(wc)
    
      End Sub
 
   </script>
 
 
</head>
<body>
  
   <form runat="server">

      <h3>WebControl Constructor Example</h3>
 
      <p>

      <asp:PlaceHolder id="PlaceHolder1"
           runat="Server"/>

      <br>
 
      <asp:Button id="Button1" 
           Text="Click to create a new TextArea" 
           OnClick="Button1_Click" 
           runat="Server" />
 
      <p>
 
   </form>
 
</body>
</html>

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
 
<head>
 
   <script runat="server">
 
      void Button1_Click(Object sender, EventArgs e) 
      {
         WebControl wc = new WebControl(HtmlTextWriterTag.Textarea);
         PlaceHolder1.Controls.Add(wc);
      }
 
   </script>
 
 
</head>
<body>
  
   <form runat="server">

      <h3>WebControl Constructor Example</h3>
 
      <p>

      <asp:PlaceHolder id="PlaceHolder1"
           runat="Server"/>

      <br>
 
      <asp:Button id="Button1" 
           Text="Click to create a new TextArea" 
           OnClick="Button1_Click" 
           runat="Server" />
 
      <p>
 
   </form>
 
</body>
</html>

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
 
<head>
 
   <script runat="server">
 
      function Button1_Click(sender : Object, e : EventArgs){
         var wc : WebControl = new WebControl(HtmlTextWriterTag.Textarea)
         PlaceHolder1.Controls.Add(wc)
      }
 
   </script>
 
 
</head>
<body>
  
   <form runat="server">

      <h3>WebControl Constructor Example</h3>
 
      <p>

      <asp:PlaceHolder id="PlaceHolder1"
           runat="Server"/>

      <br>
 
      <asp:Button id="Button1" 
           Text="Click to create a new TextArea" 
           OnClick="Button1_Click" 
           runat="Server" />
 
      <p>
 
   </form>
 
</body>
</html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

WebControl Class | WebControl Members | System.Web.UI.WebControls Namespace | WebControl Constructor Overload List | System.Web.UI.HtmlTextWriterTag | TagKey

Syntax based on .NET Framework version 1.1.
Documentation version 1.1.1.

Send comments on this topic.

© Microsoft Corporation. All rights reserved.