Click here to Skip to main content
15,906,569 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
For textbox in c#, how to I get textbox to wait unti im finished typing all the characters before checking the count? If I have a condition to check if a variable length is less than 6 and issue a message if it is, i want to wait until i input all the characters before checking, rather than issuing the message after every character.

What I have tried:

Textbox character length check
Posted
Updated 9-Apr-19 7:49am

It's simpler to wait until "submit" to check "all" fields and show only 1 or 2 top messages, instead of trying to control "focus".

You can post errors in a message area from OnLostFocus and the like (so user can "go back"), but anything more requires "programming" (keyboard, mouse, "touch", activate / deactivate, etc.).
 
Share this answer
 
You should use client side validation for same.

You can check onblur event for the length of a characters inserted into the textbox.

HTML
<input type="text" onblur="return myFunction()">



Script
JavaScript
function myFunction(){

var iCount = $("#txtValue").val();

if(iCount > 6){

return true;

}else{

alert("Your alert message");
return false;
}

}


Or

You can set validation on button click event also instead of blur or textchanged event.

If you are using server side textbox (asp:) then set AutoPostBack = False
 
Share this answer
 
v2
Thank you! Your script option worked for me.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900