On a web page, I used the regularexpressionvalidator control to verify the textbox. Then I wrote another JS function to call the Click Event of the button. The following problem occurs:
1. Enter the textbox and click the button to trigger JS function verification.
2. You can trigger regularexpressionvalidator verification when entering textbox.
3. When the textbox input is obviously incorrect, clicking the button cannot trigger regularexpressionvalidator to verify the control on the page.
My JS functions are as follows:
Function check_value (FRM)
{
VaR condate1_frm.txt date. value;
Condate = condate. Replace (/-/g ,"\/");
VaR time0 = new date ();
VaR time1 = new date (condate );
VaR date0 = date. parse (time0 );
VaR date1 = date. parse (time1 );
If (date1> time0)
{
Alert ("the last contact date cannot be later than today's date. ");
Return false;
}
}
Then when I load the page:
Btnadd. attributes ["onclick"] = "javascript: Return check_value (" + this. ID + ");"; the problem lies in 3, and causesvalidation is true.
ModifyCodeTo solve this problem:
Btnadd. attributes ["onclick"] = "javascript:If (page_clientvalidate ())Return check_value ("+ this. ID + ");";
The preceding section added that if the requiredfieldvalidator control is verified, the JS function is called and the test is successful.