Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8716003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:58:29+00:00 2026-06-13T05:58:29+00:00

I have my website built in ASP.NET 2.0 and C#. I have textbox called

  • 0

I have my website built in ASP.NET 2.0 and C#. I have textbox called tbCode where a user enters a code. I am trying to check that entered value against multiple values in the code behind on a button click.

This is my mark up so far.

 protected void btUpdate_Click(object sender, EventArgs e)
{


    if ((this.tbcode.Text.Trim().ToUpper() != "AB12") ||(this.tbcode.Text.Trim().ToUpper() != "DE14") || (this.tbcode.Text.Trim().ToUpper() != "XW16"))
    {
        lbmessage.Text = "Invalid Promo code. Please enter again";
    }
    else if ((this.tbcode.Text.Trim().ToUpper() == "AB12") || (this.tbcode.Text.Trim().ToUpper() == "DE14") || (this.tbcode.Text.Trim().ToUpper() == "XW16"))
    {
        Order.Shipping.Cost = 0;
        this.lShipping.Text = Order.Shipping.Cost.ToString("c");
        this.lSubtotal.Text = Order.Subtotal.ToString("c");
        this.lTotal.Text = Order.TotalCost.ToString("c");
        Order.PomoCode = this.tbcode.Text.Trim().ToUpper();
        lbmessage.Text = "Promo Code Applied.";
    }
    else
    {
        this.lShipping.Text = Order.Shipping.Cost.ToString("c");
        this.lSubtotal.Text = Order.Subtotal.ToString("c");
        this.lTotal.Text = Order.TotalCost.ToString("c");

    }

}

when i hit the button its always saying invalid code. not sure where am i making the mistake. It works perfectly if I am checking against just one value rather than the 3.

Thanks and appreciate it

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:58:30+00:00Added an answer on June 13, 2026 at 5:58 am

    Here is likely what you wanted to do:

    protected void btUpdate_Click(object sender, EventArgs e)
    {
        string tbcodeValue = this.tbcode.Text.Trim().ToUpper();
    
        string[] validCodes = new string[] { "AB12", "DE14", "XW16" };
        if (!validCodes.Contains(tbcodeValue))
        {
            lbmessage.Text = "Invalid Promo code. Please enter again";
        }
        else 
        {
            Order.Shipping.Cost = 0;
            this.lShipping.Text = Order.Shipping.Cost.ToString("c");
            this.lSubtotal.Text = Order.Subtotal.ToString("c");
            this.lTotal.Text = Order.TotalCost.ToString("c");
            Order.PomoCode = tbcodeValue;
            lbmessage.Text = "Promo Code Applied.";
        }
    }
    

    First off, you were calling this.tbcode.Text.Trim().ToUpper() all over the place. That really clutters up your code and makes it hard to read. Assigning that to a variable not only makes the code cleaner, but avoids performing all of those string manipulation functions over and over.

    Next, it appears that your intent is to say, “if the textbox value isn’t any of these values, run some code saying it’s invalid. The easiest way to do that is to put all of the valid values into a container of some sort and see if it contains the value you’re interested in. Your next block of code is basically for, “if it is one of the valid values”. So if it does contain the string then it is valid. As for your else, I couldn’t figure out what the intent of it was. Either the string is invalid, or it’s valid. I don’t see any third case there, so I just removed it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built an ASP.NET MVC 2 website that I am hosting with Rackspace
Background: I have a website that has been built with ASP.NET 2.0 and is
I am trying this. I have built asp.net website. When I publish to IIS
I have a website that is built in ASP.NET 3.5 & SQL Server 2005,
I have an ASP.NET website that I built that has grown considerably in size
Hi, I have built a ASP.NET MVC website that uses Membership, this works fine.
I have a website built with ASP.NET (3.5) and want add some level of
I have a website which displays a lot of photos, built with asp.net and
I have built a MVC website on IIS6. I used the built-in ASP.NET Security
I have built an ASP.NET MVC 3 web application (with exlusively Razor/cshtml pages) that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.