TextBox コンストラクタ
TextBox クラスの新しいインスタンスを初期化します。
Public Sub New()
[C#]
public TextBox();
[C++]
public: TextBox();
[JScript]
public function TextBox();
解説
このコンストラクタを使用して、 TextBox クラスの新しいインスタンスを作成し、初期化します。
TextBox のインスタンスの初期プロパティ値を次の表に示します。
プロパティ | 初期値 |
---|---|
TagKey | HtmlTextWriterTag.Input |
使用例
[Visual Basic, C#] ctor コンストラクタを使用して、ページに TextBox コントロールを動的に追加する方法を次の例に示します。
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
Protected Sub Page_Load(sender As Object, e As EventArgs)
' Create UserTextBox TextBox control.
Dim UserTextBox As 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)
End Sub
Protected Sub Submit_Click(sender As Object, e As EventArgs)
' Retrieve the UserTextBox TextBox control from the TextBoxControlPlaceHolder
' PlaceHolder control.
Dim TempTextBox As TextBox = CType(TextBoxControlPlaceHolder.FindControl("UserTextBox"), TextBox)
' Display the Text property.
Message.Text = "The TextBox control above is dynamically generated. <br> You entered: " & _
TempTextBox.Text
End Sub
</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>
[C#]
<%@ 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>
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
TextBox クラス | TextBox メンバ | System.Web.UI.WebControls 名前空間 | TagKey