how can apply maxLength limit in textBox when is TextMode="MultiLine" ? [modified]
-
hi ... i want to apply max length limit in textBox control in asp.net when set textMode="muliline" . i search in internet and get follow description from : http://www.google.com/url?sa=t&ct=res&cd=3&url=http%3A%2F%2Fwww.karamasoft.com%2FWhitePapers%2FJavaScript-Tips-Part1.pdf&ei=ZYPuRri_KZy2QaigzM4F&usg=AFQjCNFZxFGslWcb9UbApb2eQjqCRZB00w&sig2=AI2pBC2KYzcO6xwn3R-sTQ
HTML input type of text element provides a built-in MaxLength property to set the maximum number of characters that the user can enter. However, the TextArea element does not have such property to limit the number of characters that can be entered. When you have an ASP.NET TextBox control with TextMode="MultiLine" in your web page, it is rendered as an HTML TextArea element and you cannot use MaxLength property to set the maximum number characters. What you can do is to define a keypress event handler for the TextBox control to check the length of the text inside the text area and cancel the event if the MaxLength is reached. JavaScript function ValidateMaxLength(evnt, str, maxLength) {var evntKeyCode = GetEventKeyCode(evnt);
// Ignore keys such as Delete, Backspace, Shift, Ctrl, Alt, Insert, Delete, Home, End, Page Up, Page Down and arrow keys var escChars = ",8,17,18,19,33,34,35,36,37,38,39,40,45,46,"; if (escChars.indexOf(',' + evntKeyCode + ',') == -1) { if (str.length >= maxLength) { alert("You cannot enter more than " + maxLength + " characters."); return false; } } return true; } ASPX C# protected void Page_Load(object sender, EventArgs e) { txtValidateMaxLength.Attributes.Add("onkeypress", "return ValidateMaxLength((window.event) ? window.event : arguments[0]
, this.value, 5)"); }but when i execute it doesn't work . i think the problem is in first parameter of "ValidateMaxLength" method !!!
can you help me ?:confused: -- modified at 1:46 Tuesday 18th September, 2007 -
hi ... i want to apply max length limit in textBox control in asp.net when set textMode="muliline" . i search in internet and get follow description from : http://www.google.com/url?sa=t&ct=res&cd=3&url=http%3A%2F%2Fwww.karamasoft.com%2FWhitePapers%2FJavaScript-Tips-Part1.pdf&ei=ZYPuRri_KZy2QaigzM4F&usg=AFQjCNFZxFGslWcb9UbApb2eQjqCRZB00w&sig2=AI2pBC2KYzcO6xwn3R-sTQ
HTML input type of text element provides a built-in MaxLength property to set the maximum number of characters that the user can enter. However, the TextArea element does not have such property to limit the number of characters that can be entered. When you have an ASP.NET TextBox control with TextMode="MultiLine" in your web page, it is rendered as an HTML TextArea element and you cannot use MaxLength property to set the maximum number characters. What you can do is to define a keypress event handler for the TextBox control to check the length of the text inside the text area and cancel the event if the MaxLength is reached. JavaScript function ValidateMaxLength(evnt, str, maxLength) {var evntKeyCode = GetEventKeyCode(evnt);
// Ignore keys such as Delete, Backspace, Shift, Ctrl, Alt, Insert, Delete, Home, End, Page Up, Page Down and arrow keys var escChars = ",8,17,18,19,33,34,35,36,37,38,39,40,45,46,"; if (escChars.indexOf(',' + evntKeyCode + ',') == -1) { if (str.length >= maxLength) { alert("You cannot enter more than " + maxLength + " characters."); return false; } } return true; } ASPX C# protected void Page_Load(object sender, EventArgs e) { txtValidateMaxLength.Attributes.Add("onkeypress", "return ValidateMaxLength((window.event) ? window.event : arguments[0]
, this.value, 5)"); }but when i execute it doesn't work . i think the problem is in first parameter of "ValidateMaxLength" method !!!
can you help me ?:confused: -- modified at 1:46 Tuesday 18th September, 2007try this one
function textboxMultilineMaxNumber(txt,maxLen){
try{
if(txt.value.length > (maxLen-1))return false;
}catch(e){
}
}runat="server" Height="103px" MaxLength="100" Width="166px" onkeypress='return textboxMultilineMaxNumber(this,100)' TextMode="MultiLine"
Jintal Patel