建站学 - 轻松建站从此开始!

建站学-个人建站指南,网页制作,网站设计,网站制作教程

当前位置: 建站学 > 网站开发 > asp.net教程 >

asp.net开发中关于textbox的一个小问题

时间:2011-03-19 10:27来源: 作者: 点击:
textbox的textmode取为multiline时,其maxlength不起作用的解决方法 方法一:  验证控件验证(经实践可行) Setting the Maxength of a TextBox when it is in Multiline, You can use RegularExPRessionValidator control as shown below <asp:TextBox ID="

textbox的textmode取为multiline时,其maxlength不起作用的解决方法

方法一:  验证控件验证(经实践可行)


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" style="Z-INDEX: 102; LEFT: 200px; POSITION: absolute; TOP: 104px" 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

 

(责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片