c# - Why onTextChanged not working in ASP.net -


this question has answer here:

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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -