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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:08:17+00:00 2026-05-31T05:08:17+00:00

I have a user control header with label to display amount of item in

  • 0

I have a user control “header” with label to display amount of item in the basket. it does something like this:

protected void Page_Load(object sender, EventArgs e)
{
    lblBasketCount.Text = Session["basketItemsCount"]!=null?Session["basketItemsCount"].ToString():"0";
}

Then I have a page that has method:

public void btnAddItemToShoppingCart_Click(object sender, EventArgs )
{
    Session["basketItemsCount"] = (from b in db.CartItems where b.crt_ID == cartId select b).Sum(p => p.item_quantity);
}

The problem is that in the page life cycle addItem Method is fired after the control is already had Page_Load event. so my label will refresh only after another reload of the page.
Edit:
Header control is declared in Master Page:

<%@ Register TagPrefix="asp" TagName="Footer" Src="~/Controls/Footer.ascx" %>
    <asp:Header ID="Header" runat="server" />

And Located in Controls folder.

I’m using WAP so its in namespace Sitename.Controls.Header

  • 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-31T05:08:18+00:00Added an answer on May 31, 2026 at 5:08 am

    Don’t use Page_Load event (or other page events) in UserControls. This will lead to issues like this.
    Instead you should use properties, methods and events in your control.

    You could for example have a property BasketCount in your UserControl:

    public String BasketCount
    {
        get { lblBasketCount.Text; }
        set { lblBasketCount.Text = value; }
    }
    

    Then your page can use this property:

    var basketCount = (from b in db.CartItems where b.crt_ID == cartId select b).Sum(p => p.item_quantity);
    Session["basketItemsCount"] = basketCount;
    MyControl.BasketCount = basketCount.ToString();
    

    To get a reference to the control in your MasterPage you should provide a public property there that maps to it:

    For example(in MasterPage):

    public Header HeaderControl
    {
         get
         {
             return Header;
         }
    }
    

    And you can call this property from one of your ContentPages in this way(f.e. if your master’s type is named “SiteMaster“):

    ((SiteMaster)Page.Master).HeaderControl.BasketCount = basketCount.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control with a div like this: <div runat=server id=pnlShippingMethods class=checkoutstep>
I have an User Control that host another controls like panel, chart controls. Right
I have this User Control XAML: <Window x:Class=MyProj.Dialog xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:shell=http://schemas.microsoft.com/winfx/2006/xaml/presentation/shell mc:Ignorable=d>
I have a user control called DashboardUserControl.ascx It has a function: public void setPagination(Boolean
I have a user control (Navigation) nested within another user control (Header) that is
I have a winforms application that I'd like to add a WPF user control
Lets say that I have a header user control in a master page, and
I have a user control with this code behind: /// <summary> /// The text
I have user control in my MVC2 app placed in the Content folder (it's
i have user control, which i render on several views. i want to show

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.