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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:35:08+00:00 2026-05-26T04:35:08+00:00

I have a user control which I would like to use output caching on,

  • 0

I have a user control which I would like to use output caching on, but it is used several times with different data.

I thought about using VaryByCustom and try to receive the ClientID of the control, but haven’t been able to find a way.

Is there a way to output cache a usercontrol based on the ClientID, or another way to identify it by its position in the DOM?

Update:
I have tried to add a hidden field and set the output caching. For the example I have set the value of the hidden field to Datetime.Now, but it still displays the same usercontrol, and not two who are different by the content.

<%@ OutputCache VaryByControl="hidMyField" Duration="120" %>
<asp:HiddenField runat="server" ID="hidMyField" Value="<%= Datetime.Now.ToString() %>"/>
  • 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-26T04:35:08+00:00Added an answer on May 26, 2026 at 4:35 am

    One of the way could be to have a server side hidden field on the control, push the user control’s client ID into it and then use VaryByControl parameter with hidden field’s ID.

    For more information/options, see this MSDN link that discusses the same problem.

    EDIT
    Using Datetime.Now.ToString() is not a good idea for two reasons! If you see the actual value for various controls, you will find it to be the same because ToString will have value up to seconds – all your control instances on the page will have almost same date/time value probably differing in milli-seconds which will give same ToString() value.
    Second issue is that DateTime.Now is non-deterministic. For caching to work, you need to have deterministic value (a value that does not changes in repeated calls) – otherwise for every page request, you will have a different value which will invalidate the cache. I suggest putting user control’s client id as a value. Yet another way would be expose a property in user control and set it to running number such as 1,2,3.. from the page.

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

Sidebar

Related Questions

I have developed a paging control that I would like to use in a
I have a grid control that I use throughout the application. I would like
I am relatively new to mod_rewrite, but have a site which I would like
I have a user control which takes a Func which it then gives to
I have a user control which has a textbox on it, now this usercontrol
I have a user control which does some validation in the ValidateChildren method which
I have a user control which displays the currently logged in user's name. I
I have a user control which uses objects as inner properties (some code is
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have developed a user-control which gets bound to an id-field and then enables

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.