Wednesday, February 1, 2012

MaximumLength client side validation for textbox in asp.net


<script type="text/javascript">    
  function textboxMultilineMaxNumber(txt, maxLen) {
            try {
                if (txt.value.length > (maxLen)) {
                    var strValue = txt.value;
                    txt.value = strValue.substring(0, 100);
                    alert("Description should not exceed more than 100 characters.");
                    return false;
                }

            } catch (e) {
            }
        }
</script> 


 <asp:TextBox ID="txtdescription" runat="server"                                               TextMode="MultiLine" Enabled="false" ValidationGroup="Search" onkeyup="return textboxMultilineMaxNumber(this,100)"></asp:TextBox>

No comments:

Post a Comment

Comments

Search

Custom Search
Protected by Copyscape Plagiarism Software