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 538301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:01:02+00:00 2026-05-13T10:01:02+00:00

Hi guys got a wired problem (well I find it a wired problem :P)

  • 0

Hi guys got a wired problem (well I find it a wired problem :P)

I have an order page done in asp.net c#, and which a user adds ingredients to a set of list boxes, once the user and finished adding items, they get combined to make a sandwich then added to another list box that shows the sandwiches and their ingredients. I also have a button to allow the user to remove the highlighted sandwich from the order, this all works fine until the page loads up with a query string that skips the adding of ingredients and just shows the sandwiches on a order, the listbox of sandwiches populates fine but I then get an error when the remove button is clicked which is

System.NullReferenceException: Object reference not set to an instance of an object.

on
CompletedSandwiches.SelectedItem.Text

the only difference is that I pass a query string “?EDIT=1”

and then on page_load I check

        if (!Page.IsPostBack)
        {
            if ((Request.QueryString["EDIT"] != null) && (Request.QueryString["EDIT"] == "1"))
            {

                GetCurrentSandwiches();
            }

            RemoveFilling.Enabled = false;
            RemoveCondiment.Enabled = false;
            CID = int.Parse(Session["CID"].ToString());

        }

GetCurrentSandwiches does the following:

 protected void GetCurrentSandwiches()
        {
            sandwichOnOrder.Clear();

            OrderManagement order = new OrderManagement();

            List<SarnieIngredients> bob = order.GetSandwichesOnOrder(int.Parse(Session["OID"].ToString()));
            List<int> ingredientIDs = new List<int>();


            foreach (SarnieIngredients sarnie in bob)
            {
                List<Ingredients> batchOfIngredients = new List<Ingredients>();
                double amount = 0.00;
                ingredientIDs = sarnie.IngredientIDs;
                foreach (int i in ingredientIDs)
                {
                    Ingredients contents =  ingredient.GetDesiredIngredientByID(i);

                    batchOfIngredients.Add(contents);
                    amount += contents.Price;
                }

                SandwichConentent sandwich = new SandwichConentent(batchOfIngredients, amount);
                sandwichOnOrder.Add(sandwich);

                CompletedSandwiches.Items.Add(sandwich.ToString());

            } 

and my remove buttons code does

        bool found = false;
        int i = 0;

        while (i < sandwichOnOrder.Count || found == false)
        {


            SandwichConentent content = sandwichOnOrder[i];
            if (content.ToString() == CompletedSandwiches.SelectedItem.Text)
            {
                CompletedSandwiches.Items.Remove(CompletedSandwiches.SelectedItem);
                sandwichOnOrder.Remove(content);
                found = true;
            }
        }

does anyone have any idea why I am having this problem?

thanks in advance Matt

edit ~ sorry I forgot to mention I know I haven’t put validation in but I check manually that there’s a item selected before I pass and when looking at the listbox in debug it is apparently null even though visually it is not.

edit 2 ~ sorry again the error occurs on this line

if (content.ToString() == CompletedSandwiches.SelectedItem.Text)

and when ?EDIT=1 is passed, it is a new page call from the main page of the web app

  • 1 1 Answer
  • 1 View
  • 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-05-13T10:01:02+00:00Added an answer on May 13, 2026 at 10:01 am

    You need one if in your remove method:

    if (CompletedSandwiches.SelectedItem.Text != null)
     ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 399k
  • Answers 399k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Thanks but that wasn't the problem, the issue was actually… May 15, 2026 at 3:59 am
  • Editorial Team
    Editorial Team added an answer The second bit is infinitely recursive: struct X2 : X… May 15, 2026 at 3:59 am
  • Editorial Team
    Editorial Team added an answer You can try Microsoft Solver Foundation. It is a mathematical… May 15, 2026 at 3:59 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.