HtmlInputText クラス
アセンブリ: System.Web (system.web.dll 内)

<ValidationPropertyAttribute("Value")> _ Public Class HtmlInputText Inherits HtmlInputControl Implements IPostBackDataHandler
[ValidationPropertyAttribute("Value")] public class HtmlInputText : HtmlInputControl, IPostBackDataHandler
[ValidationPropertyAttribute(L"Value")] public ref class HtmlInputText : public HtmlInputControl, IPostBackDataHandler

HtmlInputText コントロールを使用して、ユーザーがテキストまたはパスワードを入力するための単一行テキスト ボックスを作成します。MaxLength プロパティは、テキスト ボックスに入力できる最大文字数を指定します。Size プロパティでは、テキスト ボックスの幅を指定できます。ユーザーによってテキスト ボックスに入力された値を確認するには、Value プロパティを使用します。Value プロパティの内容がサーバーへのポスト間で変更された場合は、HtmlInputText コントロールが提供する ServerChange イベントが発生します。これにより、イベントが発生するたびに命令のカスタム セットを実行するイベント ハンドラを作成できます。
![]() |
---|
HtmlInputText コントロールには、サーバーへのポストバックの手段は組み込まれていません。コントロールの値をサーバーに送り返すには、HtmlButton コントロールなどのサーバーへのポストをサポートしている他のコントロールを Web ページ上に用意する必要があります。 |
複数行のテキスト ボックスを作成するには、HtmlTextArea コントロールを使用します。
HtmlInputText のインスタンスの初期プロパティ値の一覧については、HtmlInputText コンストラクタのトピックを参照してください。

HtmlInputText コントロールを使用してユーザー入力を取得する方法を次のコード例に示します。
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Protected Sub AddButton_Click(sender As Object, e As EventArgs) Dim Answer As Integer Answer = Convert.ToInt32(Value1.Value) + Convert.ToInt32(Value2.Value) AnswerMessage.InnerHtml = Answer.ToString() End Sub </script> </head> <body> <form runat="server"> <h3> HtmlInputText Example </h3> <table> <tr> <td colspan="5"> Enter integer values into the text boxes. <br> Click the Add button to add the two values. <br> Click the Reset button to reset the text boxes. </td> </tr> <tr> <td colspan="5"> </td> </tr> <tr align="center"> <td> <input ID="Value1" Type="Text" Size="2" MaxLength="3" Value="1" runat="server"/> </td> <td> + </td> <td> <input ID="Value2" Type="Text" Size="2" MaxLength="3" Value="1" runat="server"/> </td> <td> = </td> <td> <span ID="AnswerMessage" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:RequiredFieldValidator ID="Value1RequiredValidator" ControlToValidate="Value1" ErrorMessage="Please enter a value.<br>" Display="Dynamic" runat="server"/> <asp:CompareValidator ID="Value1MinCompareValidator" ControlToValidate="Value1" Operator="LessThan" Type="Integer" ValueToCompare="100" ErrorMessage="Please enter an integer less than 100.<br>" Display="Dynamic" runat="server"/> <asp:CompareValidator ID="Value1MaxCompareValidator" ControlToValidate="Value1" Operator="GreaterThan" Type="Integer" ValueToCompare="0" ErrorMessage="Please enter an integer greater than 0.<br>" Display="Dynamic" runat="server"/> </td> <td colspan="2"> <asp:RequiredFieldValidator ID="Value2RequiredValidator" ControlToValidate="Value2" ErrorMessage="Please enter a value.<br>" Display="Dynamic" runat="server"/> <asp:CompareValidator ID="Value2MinCompareValidator" ControlToValidate="Value2" Operator="LessThan" Type="Integer" ValueToCompare="100" ErrorMessage="Please enter an integer less than 100.<br>" Display="Dynamic" runat="server"/> <asp:CompareValidator ID="Value2MaxCompareValidator" ControlToValidate="Value2" Operator="GreaterThan" Type="Integer" ValueToCompare="0" ErrorMessage="Please enter an integer greater than 0.<br>" Display="Dynamic" runat="server"/> </td> <td>   </td> </tr> <tr align="center"> <td colspan="4"> <input Type="Submit" Name="AddButton" Value="Add" OnServerClick="AddButton_Click" runat="server"/> <input Type="Reset" Name="AddButton" Value="Reset" runat="server"/> </td> <td> </td> </tr> </table> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> protected void AddButton_Click(Object sender, EventArgs e) { int Answer; Answer = Convert.ToInt32(Value1.Value) + Convert.ToInt32(Value2.Value); AnswerMessage.InnerHtml = Answer.ToString(); } </script> </head> <body> <form runat="server"> <h3> HtmlInputText Example </h3> <table> <tr> <td colspan="5"> Enter integer values into the text boxes. <br> Click the Add button to add the two values. <br> Click the Reset button to reset the text boxes. </td> </tr> <tr> <td colspan="5"> </td> </tr> <tr align="center"> <td> <input ID="Value1" Type="Text" Size="2" MaxLength="3" Value="1" runat="server"/> </td> <td> + </td> <td> <input ID="Value2" Type="Text" Size="2" MaxLength="3" Value="1" runat="server"/> </td> <td> = </td> <td> <span ID="AnswerMessage" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:RequiredFieldValidator ID="Value1RequiredValidator" ControlToValidate="Value1" ErrorMessage="Please enter a value.<br>" Display="Dynamic" runat="server"/> <asp:CompareValidator ID="Value1MinCompareValidator" ControlToValidate="Value1" Operator="LessThan" Type="Integer" ValueToCompare="100" ErrorMessage="Please enter an integer less than 100.<br>" Display="Dynamic" runat="server"/> <asp:CompareValidator ID="Value1MaxCompareValidator" ControlToValidate="Value1" Operator="GreaterThan" Type="Integer" ValueToCompare="0" ErrorMessage="Please enter an integer greater than 0.<br>" Display="Dynamic" runat="server"/> </td> <td colspan="2"> <asp:RequiredFieldValidator ID="Value2RequiredValidator" ControlToValidate="Value2" ErrorMessage="Please enter a value.<br>" Display="Dynamic" runat="server"/> <asp:CompareValidator ID="Value2MinCompareValidator" ControlToValidate="Value2" Operator="LessThan" Type="Integer" ValueToCompare="100" ErrorMessage="Please enter an integer less than 100.<br>" Display="Dynamic" runat="server"/> <asp:CompareValidator ID="Value2MaxCompareValidator" ControlToValidate="Value2" Operator="GreaterThan" Type="Integer" ValueToCompare="0" ErrorMessage="Please enter an integer greater than 0.<br>" Display="Dynamic" runat="server"/> </td> <td>   </td> </tr> <tr align="center"> <td colspan="4"> <input Type="Submit" Name="AddButton" Value="Add" OnServerClick="AddButton_Click" runat="server"/> <input Type="Reset" Name="AddButton" Value="Reset" runat="server"/> </td> <td> </td> </tr> </table> </form> </body> </html>


System.Web.UI.Control
System.Web.UI.HtmlControls.HtmlControl
System.Web.UI.HtmlControls.HtmlInputControl
System.Web.UI.HtmlControls.HtmlInputText
System.Web.UI.HtmlControls.HtmlInputPassword


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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- HtmlInputText クラスのページへのリンク