Answered by:
FormView validation problem

Question
-
User1510859543 posted
We have a FormView (see sample markup below) that is not bypassing validation on the Cancel button. I have a feeling that it has something to do with required="required" on the TextBox (input) control but not sure why. I would prefer not to use the RequiredFieldValidator unless it is the only option. When a user clicks the "Cancel" button it attempts to validate all TextBox controls even though the button has CausesValidation="False". Any way around this?
<asp:FormView ID="fvRegistration" runat="server" DataKeyNames="RegistrationID" DataSourceID="SqlRegistrations" DefaultMode="Insert"> <InsertItemTemplate> <table> <tr> <td style="text-align: right"> First Name:<span class="required">*</span> </td> <td> <asp:TextBox ID="txtOrgFirstName" runat="server" Text='<%# Bind("OrgFirstName") %>' MaxLength="20" required="required" /> </td> </tr> ...... <tr> <td style="text-align: center"> <asp:Button ID="BtnInsert" runat="server" CausesValidation="True" CommandName="Insert" Text="Submit" OnClientClick="return submitForm('info_form');" /> </td> <td style="text-align: center;"> <asp:Button ID="BtnInsertCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" ForeColor="#FF3300" /> </td> </tr> </table> </InsertItemTemplate> </asp:FormView>
Tuesday, October 3, 2017 1:56 PM
Answers
-
User475983607 posted
So there is no way to bypass the client API validation?
You are in control of the validation API used in the application. I assume you are using HTML 5 validation which, as far as I know, is a different API than what ASP Server Control Validation uses. Unless something changed in the latest framework.
You need to settle on a validation strategy and use that same strategy throughout the application.
https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, October 3, 2017 2:48 PM
All replies
-
User475983607 posted
You need to settle on the validation you intend to use. If you are using validation server controls, then remove the client API validation.
Tuesday, October 3, 2017 2:06 PM -
User1510859543 posted
So there is no way to bypass the client API validation?
Tuesday, October 3, 2017 2:28 PM -
User475983607 posted
So there is no way to bypass the client API validation?
You are in control of the validation API used in the application. I assume you are using HTML 5 validation which, as far as I know, is a different API than what ASP Server Control Validation uses. Unless something changed in the latest framework.
You need to settle on a validation strategy and use that same strategy throughout the application.
https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, October 3, 2017 2:48 PM -
User1510859543 posted
Too bad if you just want to cancel entry. I did notice that you can click the back button to exit and it bypasses checking.
Tuesday, October 3, 2017 3:56 PM -
User475983607 posted
dlchase
Too bad if you just want to cancel entry. I did notice that you can click the back button to exit and it bypasses checking.
I assume you settled on HTML 5 validation? Then simply do an HTTP GET rather than a post. Or use a button type rather than a submit. Did you read the posted link?
Tuesday, October 3, 2017 4:53 PM -
User1510859543 posted
Yes, I read the link. I tried the js function below in OnClientClick property and it did bypass the API.
function goBack() { if (confirm('Are you sure you want to Cancel?') === true) { window.history.back(); } }
Tuesday, October 3, 2017 5:07 PM