Button.Text 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置在 Button 控件中显示的文本标题。
public:
property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string Text { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Text : string with get, set
Public Property Text As String
属性值
在 Button 控件中显示的文本标题。 默认值是 Empty。
实现
- 属性
示例
下面的代码示例演示如何使用 Text 属性指定控件中显示的 Button 标题。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Manually register the event-handling method for
// the Click event of the Button control.
Button1.Click += new EventHandler(this.GreetingBtn_Click);
}
void GreetingBtn_Click(Object sender,
EventArgs e)
{
// When the button is clicked,
// change the button text, and disable it.
Button clickedButton = (Button)sender;
clickedButton.Text = "...button clicked...";
clickedButton.Enabled = false;
// Display the greeting label text.
GreetingLabel.Visible = true;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Simple Button Example</h3>
<asp:Button id="Button1"
Text="Click here for greeting..."
OnClick="GreetingBtn_Click"
runat="server"/>
<br />
<br />
<asp:Label ID="GreetingLabel" runat="server"
Visible="false" Text="Hello World!" />
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub GreetingBtn_Click(ByVal sender As Object, _
ByVal e As EventArgs)
' When the button is clicked,
' change the button text, and disable it.
Dim clickedButton As Button = sender
clickedButton.Text = "...button clicked..."
clickedButton.Enabled = False
' Display the greeting label text.
GreetingLabel.Visible = True
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Button Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Simple Button Example</h3>
<asp:Button id="Button1"
Text="Click here for greeting..."
OnClick="GreetingBtn_Click"
runat="server"/>
<br />
<br />
<asp:Label ID="GreetingLabel" runat="server"
Visible="false" Text="Hello World!" />
</div>
</form>
</body>
</html>
注解
Text使用 属性可指定要在控件中显示的Button标题或确定标题。
设置此属性的值时,可以使用设计器工具自动保存到资源文件。 有关详细信息,请参阅 LocalizableAttribute 和 全球化和本地化。