3

I use a button click with the asp.net validation group and client side validation (javascript). It give the first preference to javascript validation if it returns true means it directly go to the serverside button click event not check the 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"** />

1 Answer 1

4

Based on your question I understand that- You need your field validations should occur first and then script should execute.

You can call Page_ClientValidate() in your client script to explicitly execute all validations and if it successful then only Client Script should be executed.

Here is a small demo on the 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 the validators in ValidationGroup "qa"**
            {
                alert("Save all 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 is required!">
        </asp:RequiredFieldValidator>
        <asp:Button ID="Button1" runat="server" ValidationGroup="qa" Text="Test Validation" OnClientClick="ClientScript()" />
    </div>
    </form>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.