c# - Why onTextChanged not working in ASP.net -
this question has answer here:
- why asp.net ontextchanged not working 2 answers
i have following textbox in asp.net page:
<asp:textbox ontextchanged="maxchar" id="txtname" width="95%" runat="server"></asp:textbox>
the following in code-behind:
protected void maxchar(object sender, eventargs e) { if (txtname.text.length > 25) { lblisvalid.text = "only 25 characters allowed"; } }
when enter text in textbox , exceed 25 character nothing displayed in label. how can fix it?
in case, max lenght, should use property of asp:textbox called maxlength="25".
but, if want send message user, recomend use jquery, it's easy:
$('#txtname').keydown(function(){ if($(this).length >= 25){ //you alert }; });
Comments
Post a Comment