This documentation is archived and is not being maintained.

Button.Text Property

Gets or sets the text caption displayed in the Button control.

[Visual Basic]
Public Property Text As String
[C#]
public string Text {get; set;}
[C++]
public: __property String* get_Text();
public: __property void set_Text(String*);
[JScript]
public function get Text() : String;
public function set Text(String);

Property Value

The text caption displayed in the Button control. The default value is String.Empty.

Remarks

Use the Text property to specify or determine the caption to display in the Button control.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Text property to specify the caption displayed in the Button control.

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

<html>
 
<head>

   <script language="VB" runat=server>

    Sub SubmitBtn_Click(sender As Object, e As EventArgs)
        Message.Text = "Hello World!!"
    End Sub 'SubmitBtn_Click

  </script>

</head>
 
<body>
   <form runat="server">

      <h3>Button Example</h3>

      Click on the submit button.<br><br>
 
      <asp:Button id="Button1"
           Text="Submit"
           OnClick="SubmitBtn_Click" 
           runat="server"/>
       
      <p>

      <asp:label id="Message" runat="server"/>
 
   </form>
 
</body>
</html>
   

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

<html>
 
<head>

   <script language="C#" runat=server>

      void SubmitBtn_Click(Object sender, EventArgs e) 
      {
         Message.Text="Hello World!!";
      }

   </script>

</head>
 
<body>
   <form runat="server">

      <h3>Button Example</h3>

      Click on the submit button.<br><br>
 
      <asp:Button id="Button1"
           Text="Submit"
           OnClick="SubmitBtn_Click" 
           runat="server"/>
       
      <p>

      <asp:label id="Message" runat="server"/>
 
   </form>
 
</body>
</html>
   

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

<html>
 
<head>

   <script language="JScript" runat=server>

      function SubmitBtn_Click(sender : Object, e : EventArgs) 
      {
         Message.Text="Hello World!!";
      }

   </script>

</head>
 
<body>
   <form runat="server">

      <h3>Button Example</h3>

      Click on the submit button.<br><br>
 
      <asp:Button id="Button1"
           Text="Submit"
           OnClick="SubmitBtn_Click" 
           runat="server"/>
       
      <p>

      <asp:label id="Message" runat="server"/>
 
   </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

Button Class | Button Members | System.Web.UI.WebControls Namespace | String.Empty

Show: