I have following code inside a button click handler. Both approaches work fine. The Page_ClientValidate()
causes an extra validation check and do processing whereas Page_IsValid
makes use of existing property.
QUESTIONS
- In case of button click, is it always guaranteed that
Page_IsValid
would have been calculated by that time? If is not guaranteed, we need to callPage_ClientValidate()
explicitly. - What are the events that happen before
Page_IsValid
is set? For such events we should not rely onPage_IsValid
UPDATE
Is it assured that the button click event handler (in JavaScript) will be called only after the validation part is completed (i.e., after Page_ClientValidate() was invoked as part of validation) ? If this is assured, can I rely on Page_IsValid?
SCRIPT
$('#btnSave').click(function (e) {
//Aproach 1
var isValid = Page_ClientValidate('');
if (isValid)
{
//Do reamining work
}
//Aproach 2
if (Page_IsValid)
{
//Do reamining work
}
});
REFERENCES: