Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Bypass Validation For Orders with Free Products with a Zero Total

Posted on 2012-04-13
1
Medium Priority
?
256 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

782 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