程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> textbox的textmode取為multiline時,其maxlength不起作用 解決方法

textbox的textmode取為multiline時,其maxlength不起作用 解決方法

編輯:.NET實例教程

方法一:  驗證控件驗證(經實踐可行)


Setting the Maxength of a TextBox when it is in Multiline, You can use RegularExpressionValidator control as shown below

<ASP:TextBox ID="txtConclusion" MaxLength="200" TextMode="MultiLine" Height="100px" Width="400px" runat="server" />
<ASP:RegularExpressionValidator ID="txtConclusionValidator1" ControlToValidate="txtConclusion" Text="超過200字" ValidationExpression="^[\s\S]{0,200}$" runat="server" />

 

方法二:彈出對話框提示
1.Html代碼

<Html>
    <HEAD>
        <title>WebForm6</title>
        <meta name="GENERATOR" Content="Microsoft Visual Studio .Net 7.1">
        <meta name="CODE_LANGUAGE" Content="C#">
        <meta name="vs_defaultClIEntScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/IE5">
        <script language="Javascript">            
            function isOver(sText,len)
            {
                var intlen=sText.value.length;
                if (intlen>len)
                {
                    alert("The content length must Less than or Equal "+len);
                    sText.focus();
                    sText.select();
                }
            }
        </script>
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <ASP:TextBox id="txtName" runat="server"
                TextMode="MultiLine" Height="112px" Width="271px"></ASP:TextBox>
      </form>
    </body>
</Html>2.cs代碼
private void Page_Load(object sender, System.EventArgs e)
        {
            this.txtName.Attributes.Add("onblur","isOver(this,1000);");
        }
方法三: 自定義控件

Multiline TextBox with MaxLength Validation
http://www.codeproject.com/KB/aspnet/Textarea_Length_Validator.ASPx


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved