0
<body>
<form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtb3" runat="server" required></asp:TextBox>
        <asp:TextBox ID="txtb2" runat="server" required></asp:TextBox>
        <asp:TextBox ID="txtb1" runat="server" required></asp:TextBox>

        <asp:Button ID="btnBack" runat="server" Text="btn 2" OnClick="btnBack_Click" />
        <asp:Button ID="btnSubmit" runat="server" Text="btn 1" OnClick="btnSubmit_Click" />

    </div>
</form>

This is my code page. I have two button and need validation in submit button but don't need validate in back button. What to do that!!!

4 Answers 4

2

You can write javascript to prevent that for back button. Following is the snippet you need.

<script  type="text/javascript">
    function setNoValidate() {
        for (var f = document.forms, i = f.length; i--;) f[i].setAttribute("novalidate", i);
        document.forms[0].submit(); // replace 0 with with actual form name, like document.formSub
    }
</script>

<asp:Button ID="btnBack" runat="server" Text="btn 2" OnClientClick="setNoValidate();" />

Update

You can use HTML5 attribute formnovalidate to escape HTML5 validation i.e. directly use <asp:Button ID="btnBack" runat="server" Text="btn 2" formnovalidate /> instead of above script. Explained here

Note: CausesValidation is to handle validation for asp.net validators not HTML5 validation.

Sign up to request clarification or add additional context in comments.

Comments

1

Use formnovalidate tag to avoid validation ---

formnovalidate="formnovalidate"

 <asp:Button ID="btnBack" runat="server" Text="btn 2" OnClick="btnBack_Click" formnovalidate="formnovalidate" />

<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="txtb3" runat="server" required></asp:TextBox>
            <asp:TextBox ID="txtb2" runat="server" required></asp:TextBox>
            <asp:TextBox ID="txtb1" runat="server" required></asp:TextBox>

            <asp:Button ID="btnBack" runat="server" Text="btn 2" OnClick="btnBack_Click" formnovalidate="formnovalidate" />
            <asp:Button ID="btnSubmit" runat="server" Text="btn 1" OnClick="btnSubmit_Click"  />

        </div>
    </form>

Comments

0

This is the right way to do :=)

<asp:Button ID="btnBack" runat="server" Text="btn 2"
      OnClick="btnBack_Click"  CausesValidation="False"/>

1 Comment

OP is asking to disable HTML5 validation, and CausesValidation is to disable asp.net validations, I have tried your solution, it does not work, it still displays html5 validation error. so downvoting your answer :=( –
0

Just add formnovalidate="formnovalidate" on the button on which you dont want html5 validation to be fired.

2 Comments

Add some explanation with answer for how this answer help OP in fixing current issue
Just add formnovalidate="formnovalidate" on the button on which you don't want the html5 validation to be fired. like below <asp:Button ID="btnBack" runat="server" Text="btn 2" OnClick="btnBack_Click" formnovalidate="formnovalidate" />

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.