Solved

Bypass Validation For Orders with Free Products with a Zero Total

Posted on 2012-04-13
1
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Razor DropDownListFor - clear selected in SelectList before creation 3 50
Adding items to a C# list incrementally 5 82
Need help for captcha 2 42
What are MicroServices? 4 67
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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