Solved

Bypass Validation For Orders with Free Products with a Zero Total

Posted on 2012-04-13
1
253 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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