c# - How to use the both JavaScript validation and asp.net validation for a control -
i use button click asp.net validation group , client side validation (javascript). give first preference javascript validation if returns true means directly go serverside button click event not check asp.net validations.
<asp:imagebutton id="img_btn_register" runat="server" imageurl="~/images/register1.png" **onclientclick="return validat_form()"** onclick="img_btn_register_click1" **validationgroup="qa"** />
based on question understand that- need field validations should occur first , script should execute.
you can call page_clientvalidate
() in client script explicitly execute validations , if successful client script should executed.
here small demo on same:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" language="javascript"> function clientscript() { if (page_clientvalidate("qa"))**// first check validators in validationgroup "qa"** { alert("save modification?"); } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:textbox id="textbox1" runat="server"></asp:textbox> <asp:requiredfieldvalidator id="requiredfieldvalidator1" validationgroup="qa" runat="server" controltovalidate="textbox1" text="*" errormessage="value in textbox1 required!"> </asp:requiredfieldvalidator> <asp:button id="button1" runat="server" validationgroup="qa" text="test validation" onclientclick="clientscript()" /> </div> </form> </body> </html>
Comments
Post a Comment