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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:06:27+00:00 2026-05-11T16:06:27+00:00

I am working on rendering a set of cart items using a user control.

  • 0

I am working on rendering a set of cart items using a user control. Each cart item can be removed via a button in the user control. When a cart item is removed I need to visually show it’s removal. However, since the cart item existed during the loading of the page it remains until the page is refreshed again. What I am after is a means to refresh the page after the work to remove the cartitem has been completed.

The code behind cart.aspx.cs looks like:

protected void Page_Init(object sender, EventArgs e)
{
    CreateCartItemControls();
}

private void CreateCartItemControls()
{
    foreach (CartItem ci in Profile.Cart.Items)
    {
        ASP.CartItemControl cic = new ASP.CartItemControl();
        cic.ItemName = ci.Name;

        cic.CartID = ci.ID;
        cic.Cost = ci.BaseCost.ToString("c");
        cic.ItemComponents = ci.Components;

        cic.CartItemRemoved += new EventHandler(CartItemRemoved);

        Content.Controls.Add(cic);
    }
}

void CartItemRemoved(object sender, EventArgs e)
{
    Master.UpdateCartItemCount();
}

Markup for CartItemControl.ascx

<%@ Control Language="C#" ClassName="CartItemControl" AutoEventWireup="true"
    CodeFile="CartItemControl.ascx.cs"
    Inherits="UserControls_CartItemControl" %>
<fieldset id="FieldSet" runat="server">
    <legend>
        <asp:HyperLink ID="ItemLink" runat="server" />
    </legend>
    <asp:ImageButton ID="RemoveCartItem" AlternateText="Remove Item" 
        ImageUrl="~/img/buttons/remove_4c.gif" runat="server"
        CommandName="Remove" OnCommand="RemoveCartItem_Command" />
    <asp:Label ID="TotalItemCost" runat="server" Text="$0.00" />
    <ol>
        <li runat="server" id="ComponentsLI" visible="false">
            <fieldset id="ComponentsFieldSet" runat="server">
                <legend>Item Components</legend>
                <asp:CheckBoxList ID="ItemComponentsCheckList"
                    runat="server" />
            </fieldset>
        </li>
    </ol>
</fieldset>

Code behind for the UserControl CartItemControl.ascx.cs

public partial class UserControls_CartItemControl
: System.Web.UI.UserControl
{
public string ItemName { get; set; }
public int CartID { get; set; }
public string Cost { get; set; }
public IDictionary<int, SoftwareComponent> ItemComponents { get; set; }

protected void Page_PreRender(object sender, EventArgs e)
{
    SetCartItemControlAttributes();
}

private void SetCartItemControlAttributes()
{
    ItemLink.Text = ItemName;
    TotalItemCost.Text = Cost;

    RemoveCartItem.CommandArgument = CartID.ToString();

    if (!ItemComponents.Count.Equals(0))
    {
        ComponentsLI.Visible = true;
        foreach (KeyValuePair<int, ItemComponent> kvp in
            ItemComponents)
        {
            ItemComponentsCheckList.Items.Add(
                new ListItem(string.Format("{0} {1}",
                    kvp.Value.ComponentName,
                    kvp.Value.ComponentCost.ToString("c")),
                    kvp.Key.ToString()));
        }
    }
}

public event EventHandler CartItemRemoved;

protected void RemoveCartItem_Command(object sender, CommandEventArgs e)
{
    int itemID;

    if (int.TryParse(e.CommandArgument.ToString(), out itemID))
    {
        Profile.Cart.RemoveCartItem(itemID);
        CartItemRemoved(sender, e);
        Parent.Controls.Remove(this);
    }
}
}
  • 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-11T16:06:27+00:00Added an answer on May 11, 2026 at 4:06 pm

    Just as you add CartItemControls to Content’s Controls collection on init, you need to remove them on RemoveCartItem_Command. Do so by either exposing your own ItemRemoved event and handling it in the main page or by calling Parent.Controls.Remove(this) inside the RemoveCartItem_Command.

    Or am I missing something?

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

Sidebar

Ask A Question

Stats

  • Questions 85k
  • Answers 85k
  • 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 The call command has this functionality built in. To quote… May 11, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer It depends on how busy the server is going to… May 11, 2026 at 5:11 pm
  • Editorial Team
    Editorial Team added an answer Well, since you're using SqlServer, why not just use Profiler?… May 11, 2026 at 5:11 pm

Related Questions

I've been playing with some algorithms on the internet for a while and I
Let G be a graph. So G is a set of nodes and set
I am working on a simple CAD program which uses OpenGL to handle on-screen
I am working on a graph in WPF, in each section there are thousands
I am working on a project right now that involves receiving a message from

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.