惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
V
Vulnerabilities – Threatpost
A
Arctic Wolf
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
Hugging Face - Blog
Hugging Face - Blog
H
Hacker News: Front Page
D
Docker
人人都是产品经理
人人都是产品经理
Attack and Defense Labs
Attack and Defense Labs
Forbes - Security
Forbes - Security
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
aimingoo的专栏
aimingoo的专栏
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Simon Willison's Weblog
Simon Willison's Weblog
腾讯CDC
WordPress大学
WordPress大学
T
Tenable Blog
P
Proofpoint News Feed
月光博客
月光博客
T
Tor Project blog
The Cloudflare Blog
罗磊的独立博客
S
Secure Thoughts
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Hacker News
The Hacker News
P
Palo Alto Networks Blog
I
Intezer
小众软件
小众软件
N
News | PayPal Newsroom
V
Visual Studio Blog
L
LINUX DO - 最新话题
W
WeLiveSecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Troy Hunt's Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
D
DataBreaches.Net
P
Privacy International News Feed
博客园 - 三生石上(FineUI控件)
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security Affairs
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
阮一峰的网络日志
阮一峰的网络日志

博客园 - 嚣张的沉默

读写txt文档 计算TextBox输入的字数 我常用的正则与SQL语句 DataSet导入到Excel 年月日联动的JS代码 用户控件的传值方法 Repeater模板列 asp.net的几个小技巧 百叶窗效果 建站安全 倒计时代码 解决SQL2000安装服务器挂起 删除.NET的最近项目 屏幕右下角弹出广告 DataSet写入、导出XML 上传图片重命名并创建文件夹 自动跳转页面带参数 微软出的AJAX控件的安装(转载) 第一次开博
限制TextBox输入字数
嚣张的沉默 · 2008-03-05 · via 博客园 - 嚣张的沉默

TextBox有一个TextMode,把它设置成MultiLine后,MaxLength就不好用了.使用这个方法便可以解决此问题
新建一个txt文档,把以下代码复制进去,然后把扩展名改为:.htc后保存.

<PUBLIC:PROPERTY name="charsize" /
<PUBLIC:ATTACH event="onkeypress" handler="doKeyPress" /
<PUBLIC:ATTACH event="onbeforepaste" handler="doBeforePaste" /
<PUBLIC:ATTACH event="onpaste" handler="doPaste" /

<SCRIPT language="JavaScript"> 
// Keep user from entering more than maxLength characters 
function doKeyPress()

    
if(!isNaN(charsize))
    

        maxLength 
= parseInt(charsize); 
        
var oTR = element.document.selection.createRange(); 
        
// Allow user to type character if at least one character is selected 
        if (oTR.text.length >= 1
            event.returnValue 
= true
        
else if (value.length > maxLength-1
            event.returnValue 
= false
    }

}
 
// Cancel default behavior 
function doBeforePaste()

    
if (!isNaN(charsize)) 
    event.returnValue 
= false
}
 
// Cancel default behavior and create a new paste routine 
function doPaste()

    
if (!isNaN(charsize))
    
{
        event.returnValue 
= false
        maxLength 
= parseInt(charsize); 
        
var oTR = element.document.selection.createRange(); 
        
var iInsertLength = maxLength - value.length + oTR.text.length; 
        
var sData = window.clipboardData.getData("Text").substr(0,iInsertLength); 
        oTR.text 
= sData; 
    }
 
}
 
</SCRIPT> 

<asp:textbox id="txtContent" runat="server" CssClass="longform" MaxLength="200" TextMode="MultiLine" Rows="3" style="BEHAVIOR: url('MaxLength.htc'); WORD-BREAK: break-all" charsize="200"> </asp:textbox>

这个 charsize="200" 就是要控制的长度