locked
User control history RRS feed

  • Question

  • User632741198 posted

    I have a user control and its loaded page .IF i click back button (history) from browser page load event not fired.its loaded from cache.kindly advise me 

    Monday, April 20, 2020 9:12 AM

All replies

  • User-719153870 posted

    Hi tanbchn,

    To disable it loads from cache, please add below code in user control's page load event:

    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.Cache.SetNoStore();

    Below is the complete demo to reproduce the issue:

    .ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCDemo01.ascx.cs" Inherits="WebFormDemo01.UCDemo01" %>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    .ascx.cs:

            protected void Page_Load(object sender, EventArgs e)
            {
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Cache.SetNoStore();
                TextBox1.Text = DateTime.Now.ToString();
                TextBox1.ReadOnly = true;
            }

    .aspx:

    <%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="WebFormDemo01.About" %>
    <%@ Register TagPrefix="UCs" TagName="UCDemo" Src="~/UCDemo01.ascx" %>
    
    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
        <h2><%: Title %>.</h2>
        <h3>Your application description page.</h3>
        <p>Use this area to provide additional information.</p>
        <UCs:UCDemo runat="server" ID="UC01" />
    </asp:Content>

    Here's the result of this demo:

    Best Regard,

    Yang Shen

    Tuesday, April 21, 2020 2:12 AM