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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:23:47+00:00 2026-05-27T22:23:47+00:00

I have a web user control, it serves some potentially intensive data calculations and

  • 0

I have a web user control, it serves some potentially intensive data calculations and I would like it to be output cached so that each page view doesn’t recalculate the data. It resides on very frequently viewed pages so it’s quite important I get it working right!

For context, it’s used on our arcade:
http://www.scirra.com/arcade/action/93/8-bits-runner

Click on stats, the data for the graphs and stats are generated from this webusercontrol.

The start of the control is as follows:

public partial class Controls_Arcade_Data_ArcadeChartData : System.Web.UI.UserControl
{
    public int GameID { get; set; }
    public Arcade.ChartDataType.ChartType Type { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {

Now the difficulty I’m having is the output cache needs to be dependant on both the GamID and the ChartType.

This control is re-used with many different combinations of GameID’s and Types, I need it to create a cache for each of these but am struggling to find out how to do this.

For example, one arcade game might pass in GameID = 93 and Type = GraphData, another might be GameID = 41 and Type = TotalPlaysData and another might be GameID = 93 but Type = TotalPlaysData. These should all return different data and have different output caches.

The control is used on the games page sort of like this (the parameters are actually set in the codebehind)

<div>Total Plays:</div>
<div class="count"><Scirra:ArcadeChartData runat="server" GameID="93" Type="TotalPlays" /></div>
<br /><br />
<div>Total Guest Plays:</div>
<div class="count"><Scirra:ArcadeChartData runat="server" GameID="93" Type="TotalGuestPlays" /></div>

etc.

Any help appreciated! I’ve spent a while looking online and it’s kept coming up as something I need to solve but can’t figure this one out.

Edit

Edit: I’ve tried adding this line to my control:
<%@ OutputCache Duration=”20″ VaryByControl=”GameID;Type” %>

But it just throws the error Object reference not set to an instance of an object. on the line where GameID is being set for the first time on the ASPX page using the control.

  • 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-27T22:23:47+00:00Added an answer on May 27, 2026 at 10:23 pm

    When a Control is retrieved from the output cache, it’s not instantiated as an instance that you can manipulate; you just get the output the Control generated, not the Control itself. For example, you can’t set properties on a cached Control from code behind, as you said in your question. The vary-by properties should be set declaratively (using an ExpressionBuilder might also work, though I haven’t tried it).

    To see in code behind whether a control has been retrieved from the output cache, check for null:

    if (this.YourControlID != null) // true if not from cache
    {
        // do stuff
    }
    

    Even with that caveat, Control output caching is a bit quirky.

    Try this:

    <%@ OutputCache Duration="20" VaryByControl="GameID;Type" Shared="true" %>
    

    The output of the Control is stored in the output cache by associating it with a certain key. With Shared="true", the cache key is the value of all specified properties, together with the Control’s ID. Without Shared="true", the cache key also includes the Page type, so the output would vary by Page — which doesn’t sound like what you want.

    If you use the Control on more than one page, be sure to use the same ID on each page if you can, since the ID is included as part of the key for the output cache. If you can’t or don’t use different IDs, you will get a new copy of the Control’s output in the cache for each unique ID. If the Controls with different IDs always have different property values anyway, that may not be an issue.

    As an alternative to the OutputCache directive, you can set an attribute on the class declaration:

    [PartialCaching(20, null, "GameID;Type", null, true)]
    public partial class Controls_Arcade_Data_ArcadeChartData : UserControl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web user control that contains several other (web user) controls and
I have an ASP.Net web user control that contains a TextBox and a calendar
I have written a user control that captures some user input and has a
I have a web user control which call some methods of an interface. Four
I got a web user control where I have controls that needs to be
I have a web user control with a dropdownlist inside of it. When the
I have an int array as a property of a Web User Control. I'd
We have an existing publicly accessible web application with user controls, data access libraries,
I have a web page that uses three controls to allow a user to
I have created a web user control (MemberDetails.ascx) which is loaded dynamically on a

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.