I have a textbox in an aspx page that has a TextChanged event attached to it. I also have a validator attached to the textbox.
When the text is changed, the validate
You can move validation to client side adding EnableClientScript="true"
attribute. Postback won't occur as check will be performed with JS.
Other than that you can check whether page is valid when performing callback function for TextChanged event so that to define whether function can proceed. You should add ValidationGroup
attribute to your validator and call Page.Validate
function specifying that group before Page.IsValid
is checked.
Upd
Here's the tip.
Add your own JS function, e.g.:
function IsValid( args ) {
if( args.value.length == 0 ) {
return false;
}
else {
return true;
}
}
In Page_Load
event add this code:
txtQuantity.Attributes[ "onchange" ] = "if ( IsValid(this) == false ) return;";
This won't mess up auto postback when input is correct, but will prevent postback otherwise.