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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:26:31+00:00 2026-05-24T14:26:31+00:00

why, in the below aspx and code behind, when Output Caching is enabled programmatically

  • 0

why, in the below aspx and code behind, when Output Caching is enabled programmatically (enabled in code behind), it does not work and has a problem?

aspx:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="ProgrammaticOutputCaching"
    CodeBehind="ProgrammaticOutputCaching.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblDate" runat="server" Font-Bold="False" Font-Names="Verdana" Font-Size="XX-Large"></asp:Label><br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Refresh" />
    </div>
    </form>
</body>
</html>

code behind:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.Public);

        // Use the cached copy of this page for the next 60 seconds.
        Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
        //Response.Cache.VaryByParams.IgnoreParams = true;

        // This additional line ensures that the browser can't
        // invalidate the page when the user clicks the Refresh button
        // (which some rogue browsers attempt to do).
        Response.Cache.SetValidUntilExpires(true);

        lblDate.Text = "The time is now:<br>" + DateTime.Now.ToString();
}

with page directive for output caching there is no problem:
mean
aspx:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="OutputCaching" CodeBehind="OutputCaching.aspx.cs" %>

<%@ OutputCache Duration="60" VaryByParam="Name;Age" Location="Server" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<asp:Label ID="lblDate" runat="server" Font-Bold="False" Font-Names="Verdana"
            Font-Size="XX-Large"></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Refresh" />
    </div>
    </form>
</body>
</html>

and
code behind:

protected void Page_Load(object sender, EventArgs e)
{
        lblDate.Text = "The time is now:<br>";
        lblDate.Text += DateTime.Now.ToString();
}

so what is the problem about programmatically?

  • 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-24T14:26:32+00:00Added an answer on May 24, 2026 at 2:26 pm
    Response.Cache
    

    All these methods do is modifiy the HTTP headers in the response which ask the browser to do something (in this case modifiy how it cache’s).

    Have you used Fiddler to see these?

    I would guess that ASP.net has changed the last-modified date (since it knows the time has changed), however there’s a few reasons why the browser would still update:

    • The browser could have caching disabled
    • The cache could have just been cleared
    • It is using some other method to decide the page needed refreshed from the server
    • The browser can request whatever it wants

    I suggest you research some of these points, however you definitely shouldn’t be relying on the browsers cache to ensure the functionality of your app.

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

Sidebar

Related Questions

SOLVED: See my solution below! using aspx with C# code behind. I have the
I want to call MyMethod in code-behind from server control in aspx page like
Below is the code of a simple html with a table layout. In FF
Below are lines from the c++ programming language template<class T > T sqrt(T );
below is my listview code example, while the products are populating, I want to
I'm attempting to do what Scott Hanselman describes below: http://www.hanselman.com/blog/MixingRazorViewsAndWebFormsMasterPagesWithASPNETMVC3.aspx I have a Web
I have a main aspx page in which there is a list of items.
In my aspx page, I have two radio buttons and a table.. if one
I find this as a funny little problem. I think the reason lies behind
I need to count number of sessions but it dose not work when I

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.