Acutually, the client validate function also works as loog as the ontextchanged event was fired. Only the client validate works before the post back caused by ontextchanged.
In fact, when you drag the ASP. net validator control to the page, when you run the page, you will find that the form has be added a property (onsubmit) and assign 'javascript: Return webform_onsubmit (); 'to this property. such as follows:
<Form name = "form1" method = "Post" Action = "test6.aspx" onsubmit = "javascript: Return webform_onsubmit ();" id = "form1">
Meanwhile, please go ahead and tip the related JavaScript function.
<SCRIPT type = "text/JavaScript">
// <! [CDATA [
Function webform_onsubmit (){
If (typeof (validatoronsubmit) = "function" & validatoronsubmit () = false) return false;
Return true;
}
//]>
</SCRIPT>
And also please notice __DopostbackFunction Code segment which be generated due to the autopostback property of textbox has been set to 'true '.
Function _ dopostback (eventtarget, eventargument ){
If (! Theform. onsubmit | (theform. onsubmit ()! = False )){
Theform. _ eventtarget. value = eventtarget;
Theform. _ eventargument. value = eventargument;
Theform. Submit ();
}
}
By now, you will found that_ DopostbackFunction will be fired beforeWebform_onsubmit ()Funtion. Hence, the situation has happend like you describled.
So, please refer to the following code to solve your problem.
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<SCRIPT type = "text/JavaScript">
Function _ dopostback (eventtarget, eventargument ){
If (typeof (page_clientvalidate) = 'function '){
Page_clientvalidate ();
If (page_isvalid)
If (! Theform. onsubmit | (theform. onsubmit ()! = False )){
Theform. _ eventtarget. value = eventtarget;
Theform. _ eventargument. value = eventargument;
Theform. Submit ();
}
Return page_isvalid;
}
Else {
If (! Theform. onsubmit | (theform. onsubmit ()! = False )){
Theform. _ eventtarget. value = eventtarget;
Theform. _ eventargument. value = eventargument;
Theform. Submit ();
}
Return true;
}
}
</SCRIPT>
<Asp: textbox id = "discountrate" runat = "server" style = "float: none; width: 50px ;"
Ontextchanged = "updatediscountedcoursefeeontextchanged" autopostback = "true" causesvalidation = "true"/> %
<Asp: rangevalidator id = "discountraterangevalidator" runat = "server" controltovalidate = "discountrate"
Minimumvalue = "0.00" maximumvalue = "100.00" type = "double" errormessage = "discount rate must be within 0-100"
Tooltip = "discount rate must be within 0-100" validationgroup = "paymentgroup" setfocusonerror = "true" display = "dynamic"> * </ASP: rangevalidator>
</Form>
</Body>
</Html>