Freigeben über


HtmlInputText.MaxLength-Eigenschaft

Ruft die maximale Anzahl der Zeichen ab, die in das Textfeld eingegeben werden können, oder legt diese fest.

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

Syntax

'Declaration
Public Property MaxLength As Integer
'Usage
Dim instance As HtmlInputText
Dim value As Integer

value = instance.MaxLength

instance.MaxLength = value
public int MaxLength { get; set; }
public:
property int MaxLength {
    int get ();
    void set (int value);
}
/** @property */
public int get_MaxLength ()

/** @property */
public void set_MaxLength (int value)
public function get MaxLength () : int

public function set MaxLength (value : int)

Eigenschaftenwert

Die maximale Anzahl der Zeichen, die in das Textfeld eingegeben werden können.

Hinweise

Mit der MaxLength-Eigenschaft geben Sie die maximale Anzahl der Zeichen an, die in das Textfeld eingegeben werden können, oder ermitteln diese.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mit der MaxLength-Eigenschaft die maximale Anzahl der Zeichen angegeben wird, die in das Textfeld eingegeben werden können.

<%@ 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">
               &nbsp;
            </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>
               &nbsp
 
            </td>
         </tr>
         <tr align="center">
            <td colspan="4">
               <input Type="Submit"
                      Name="AddButton"
                      Value="Add"
                      OnServerClick="AddButton_Click"
                      runat="server"/>
               &nbsp;&nbsp;&nbsp;
               <input Type="Reset"
                      Name="AddButton"
                      Value="Reset"
                      runat="server"/>
            </td>
            <td>
               &nbsp;
            </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">
               &nbsp;
            </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>
               &nbsp
 
            </td>
         </tr>
         <tr align="center">
            <td colspan="4">
               <input Type="Submit"
                      Name="AddButton"
                      Value="Add"
                      OnServerClick="AddButton_Click"
                      runat="server"/>
               &nbsp;&nbsp;&nbsp;
               <input Type="Reset"
                      Name="AddButton"
                      Value="Reset"
                      runat="server"/>
            </td>
            <td>
               &nbsp;
            </td>
         </tr>
      </table>


   </form>

</body>
</html>

Plattformen

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 unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

HtmlInputText-Klasse
HtmlInputText-Member
System.Web.UI.HtmlControls-Namespace
Size

Weitere Ressourcen

HTML-Serversteuerelemente