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

  • Home
  • SEARCH
  • 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

Related Questions

I am working on pdf reader app.i am using gestures for rendering next page
I'm using HaXml to transform a XML file and it's all quite working nicely.
I am developing a CAD application using Delphi2010 and OpenGL. Currently, i am working
When working with text in Flash, I often encounter the following problem: http://www.aino.se/media/i/subpixel.png This
I'm following the tutorial here: http://guides.rubyonrails.org/getting_started.html Everything was working fine until I tried 8.1
Working on a end of the year project for school and chose to create
Working with some basic java apps on CentOS 5 linux and I have my
Working on Ubuntu 10.04 Lucid webserver (linode). Followed these instructions to install wkhtmltopdf link
While working with the sockets library in python 2.7, I am encountering an issue
I'm attempting to save an OpenGL created scene as a TBitmap. The problem I'm

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.