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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:18:36+00:00 2026-05-22T02:18:36+00:00

I’m using C# ASP.NET, and I’ve got a submission page which, when you click

  • 0

I’m using C# ASP.NET, and I’ve got a submission page which, when you click the add product link, opens a popup “add product” page that has a dropdown list of products which can be added to a submission. Business rules dictate there can be only one instance of each product on any submission, so I’ve run two separate switch case statements, one to eliminate items from the drop down list once they’ve been selected in the popup, and one which queries the db to determine if there are any products already associated with the submission, and if so, eliminate those options from the drop down as well. Once the user selects an item from the dropdown, a panel for that product is made visible for user input.

Both of these switch cases function, in that they eliminate the items which should not be available, but since I put in the queried switch case, the panels no longer become visible upon selection. When I remove the queried switch case, the panels do become visible upon selection, but the products which are already associated with the submission are still available in the dropdown.

I know there is a conflict here somewhere, but I’m racked as to what it is as this is my first go at programming. The code is below. Please disregard the queries themselves; this is a non-active training project and my handler forbade parameterization because he wanted me to learn basics first. I understand the injection vulnerabilities.

    public partial class AddProduct : System.Web.UI.Page
{


protected void BtnAddProduct_Click(object sender, EventArgs e)
{
    switch (DdlProductList.SelectedValue)
    {
        case "1":
            PanelEpl.Visible = true;
            DdlProductList.Items.Remove(DdlProductList.SelectedItem);
            break;
        case "2":
            PanelProf.Visible = true;
            DdlProductList.Items.Remove(DdlProductList.SelectedItem);
            break;
        case "3":
            PanelCrime.Visible = true;
            DdlProductList.Items.Remove(DdlProductList.SelectedItem);
            break;
        case "4":
            PanelFid.Visible = true;
            DdlProductList.Items.Remove(DdlProductList.SelectedItem);
            break;
        case "5":
            PanelNotProf.Visible = true;
            DdlProductList.Items.Remove(DdlProductList.SelectedItem);
            break;
        case "6":
            PanelPriv.Visible = true;
            DdlProductList.Items.Remove(DdlProductList.SelectedItem);
            break;
        case "7":
            PanelPub.Visible = true;
            DdlProductList.Items.Remove(DdlProductList.SelectedItem);
            break;
        default:

                break;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        string x = Request.QueryString["SubId"];
        string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
        string displayQuery = "SELECT CustName, CustAdd, CustCity, CustState, CustZip FROM Customer WHERE SubId =" + x;
        string broQuery = "SELECT EntityType FROM Broker WHERE SubId =" + x;
        string ddlQuery = "SELECT ProductId FROM SubmissionProducts WHERE SubmissionId =" + x;
        using (SqlConnection displayConn = new SqlConnection(connectionString))
        {
            displayConn.Open();
            SqlCommand DlistCmd = new SqlCommand(ddlQuery, displayConn);

            using (SqlDataReader Ddldr = DlistCmd.ExecuteReader())
            {
                while (Ddldr.Read())
                {

                    switch (Ddldr.GetInt32(0))
                    {
                        case 1:
                            DdlProductList.Items.RemoveAt(1);
                            break;
                        case 2:
                            DdlProductList.Items.RemoveAt(2);
                            break;
                        case 3:
                            DdlProductList.Items.RemoveAt(3);
                            break;
                        case 4:
                            DdlProductList.Items.RemoveAt(4);
                            break;
                        case 5:
                            DdlProductList.Items.RemoveAt(5);
                            break;
                        case 6:
                            DdlProductList.Items.RemoveAt(6);
                            break;
                        case 7:
                            DdlProductList.Items.RemoveAt(7);
                            break;
                        default:
                            break;
                    }

                }

            }
  • 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-05-22T02:18:37+00:00Added an answer on May 22, 2026 at 2:18 am

    I think you are not considering the Page postback state. Put your page_load code under the If(!IsPostBack) condition:

    protected void Page_Load(object sender, EventArgs e)
    {
     If(!IsPostBack)
     {
        string x = Request.QueryString["SubId"];
        string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
        string displayQuery = "SELECT CustName, CustAdd, CustCity, CustState, CustZip FROM Customer WHERE SubId =" + x;
        string broQuery = "SELECT EntityType FROM Broker WHERE SubId =" + x;
        string ddlQuery = "SELECT ProductId FROM SubmissionProducts WHERE SubmissionId =" + x;
        using (SqlConnection displayConn = new SqlConnection(connectionString))
        {
            displayConn.Open();
            SqlCommand DlistCmd = new SqlCommand(ddlQuery, displayConn);
    
            using (SqlDataReader Ddldr = DlistCmd.ExecuteReader())
            {
                while (Ddldr.Read())
                {
    
                    switch (Ddldr.GetInt32(0))
                    {
                        case 1:
                            DdlProductList.Items.RemoveAt(1);
                            break;
                        case 2:
                            DdlProductList.Items.RemoveAt(2);
                            break;
                        case 3:
                            DdlProductList.Items.RemoveAt(3);
                            break;
                        case 4:
                            DdlProductList.Items.RemoveAt(4);
                            break;
                        case 5:
                            DdlProductList.Items.RemoveAt(5);
                            break;
                        case 6:
                            DdlProductList.Items.RemoveAt(6);
                            break;
                        case 7:
                            DdlProductList.Items.RemoveAt(7);
                            break;
                        default:
                            break;
                    }
    
                }
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.