Solved

Bypass Validation For Orders with Free Products with a Zero Total

Posted on 2012-04-13
1
244 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

13 Experts available now in Live!

Get 1:1 Help Now