Client function doesn't works if you set the ASP. NET Server Control autopostback to 'tru

Source: Internet
Author: User

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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.