Export (0) Print
Expand All

TextBox Constructor

Initializes a new instance of the TextBox class.

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

public TextBox ()
public TextBox ()
public function TextBox ()

Use this constructor to create and initialize a new instance of the TextBox class.

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

Property

Initial value

TagKey

HtmlTextWriterTag.Input

The following code example demonstrates how to use the TextBox constructor to dynamically add a TextBox control to the page.

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

<html> 

<head>

   <script runat="server">

      protected void Page_Load(Object sender, EventArgs e)
      {

         // Create UserTextBox TextBox control.
         TextBox UserTextBox = new TextBox();

         // Configure the UserTextBox TextBox control.
         UserTextBox.ID = "UserTextBox";
         UserTextBox.Columns = 50;


         // Add UserTextBox TextBox control to the Controls collection 
         // of the TextBoxControlPlaceHolder PlaceHolder control.
         TextBoxControlPlaceHolder.Controls.Add(UserTextBox);

      }

      protected void Submit_Click(Object sender, EventArgs e)
      {

         // Retrieve the UserTextBox TextBox control from the TextBoxControlPlaceHolder
         // PlaceHolder control.
         TextBox TempTextBox = (TextBox)TextBoxControlPlaceHolder.FindControl("UserTextBox");

         // Display the Text property.
         Message.Text = "The TextBox control above is dynamically generated. <br> You entered: " + 
                        TempTextBox.Text;

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> TextBox Constructor Example </h3>

      Enter some text and click the Submit button. <br><br>

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

      <br><br>
 
      <asp:Button ID="SubmitButton"
           Text="Submit"
           OnClick="Submit_Click"
           runat="server"/>

      <br><br>

      <asp:Label ID="Message"
           runat="server"/>


   </form>

</body>
</html>

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

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft