Solved

Bypass Validation For Orders with Free Products with a Zero Total

Posted on 2012-04-13
1
245 Views
Last Modified: 2012-04-18
Hello,

We have a website running Validation when the user clicks on the submit button to pay for the ordered products. If the user did not enter something correctly, they see a pop up message displaying whatever they did not enter correctly that cause the invalidation.  I need to be able to bypass this validation check if the order total = $0 (for free products).  

How do we set the page to ignore the validation process for free products and to check all the necessary fields for paying orders? Is there a way to do an If statement that causes validation = true is the order total field > 0?


This is the button code:

<asp:LinkButton runat="server" ID="GoToCheckoutButton" CausesValidation="true"  OnClick="GoToCheckoutButton_Click" Text="<span>Complete Purchase</span>" CssClass="text-button large" />  

and this is the validation summary:


<asp:ValidationSummary runat="server" ID="ValSummary" DisplayMode="List" ShowSummary="false" ShowMessageBox="true"  />
<asp:RequiredFieldValidator runat="server" ID="RFV_CardType" Display="None" ControlToValidate="CardTypeDropDown" ErrorMessage="Please select the credit card type." />
<asp:RequiredFieldValidator runat="server" ID="RFV_CardNumber" Display="None" ControlToValidate="CardNumberTextBox" ErrorMessage="Please enter credit card number." />
<asp:RequiredFieldValidator runat="server" ID="RFV_SecurityCode" Display="None" ControlToValidate="SecurityCodeTextBox" ErrorMessage="Please enter the security code." />
<asp:RequiredFieldValidator runat="server" ID="RFV_NameOnCard" Display="None" ControlToValidate="NameOnCardTextBox" ErrorMessage="Please enter the name on card."  />
<asp:RequiredFieldValidator runat="server" ID="RFV_ExpirationMonth" Display="None" ControlToValidate="MonthDropDownList" ErrorMessage="Please select the expiration month." />
<asp:RequiredFieldValidator runat="server" ID="RFV_ExpirationYear" Display="None" ControlToValidate="YearDropDownList" ErrorMessage="Please select the expiration year." />
<asp:RequiredFieldValidator runat="server" ID="RFV_FirstName" Display="None" ControlToValidate="FirstNameTextBox" ErrorMessage="Please enter the first name." />
<asp:RequiredFieldValidator runat="server" ID="RFV_LastName" Display="None" ControlToValidate="LastNameTextBox" ErrorMessage="Please enter the last name." />
<asp:RequiredFieldValidator runat="server" ID="RFV_Address1" Display="None" ControlToValidate="BillingAddressLine1TextBox" ErrorMessage="Please enter the address line 1." />
<asp:RequiredFieldValidator runat="server" ID="RFV_City" Display="None" ControlToValidate="CityTextBox" ErrorMessage="Please enter the city." />
<asp:RequiredFieldValidator runat="server" ID="RFV_ZipPostalCode" Display="None" ControlToValidate="ZipTextBox" ErrorMessage="Please enter the zip or postal code." />    
<asp:RequiredFieldValidator runat="server" ID="RFV_EmailAddress" Display="None" ControlToValidate="EmailAddressTextBox" ErrorMessage="Please enter the receipt email address." />
<asp:RegularExpressionValidator ID="REV_CreditCardNumber" runat="server" ControlToValidate="CardNumberTextBox" Display="None" ErrorMessage="Credit card number is not a valid card number." ValidationExpression="^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$" />
<asp:RegularExpressionValidator ID="REV_SecurityCode" runat="server" ControlToValidate="SecurityCodeTextBox" Display="None" ErrorMessage="Securtiy code is 3 or 4 digits." ValidationExpression="[0-9]{3,4}" />
<asp:RegularExpressionValidator ID="REV_EmailAddress" runat="server" Display="None" ErrorMessage="Please enter a valid email address." ControlToValidate="EmailAddressTextBox" ValidationExpression="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" />

Thank you!
0
Comment
Question by:TheUndecider
1 Comment
 
LVL 12

Accepted Solution

by:
CmdoProg2 earned 500 total points
ID: 37851303
In your code set each of the appropriate validator's enabled property to false when total is 0.  Validation control default to true, which probably the majority of the situation.

//C#
if (totalField = 0)
  { 
    RFV_CardType.Enabled = false;
    // rest of validators
  }
'VB
IF totalField = 0 Then
  RFV_CardType.Enabled = False
  ' rest of validators
End If

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now