More in this section

Forums / Developing with Sitefinity / CacheSubstitutionUserControl and button event

CacheSubstitutionUserControl and button event

2 posts, 0 answered
  1. Hamza
    Hamza avatar
    8 posts
    20 May 2008
    28 Dec 2009
    Link to this post

    I've created a control which shows data from my database. However, I want the rest of the page to be cached. Hence I converted it into a CacheSubstitutionUserControl. Everything worked fine, till I click on a Button inside the same control. This is what is happening...
    - I click on the Button once, it reloads the page and the Button_Click event is not even fired.
    - I click on it again, the second time the Button_Click event fires and does what it is supposed to do.

    - If I convert my control back to a regular UserControl, everything works fine, however the content is now cached.

    Below is the code for my control.

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyControl.ascx.cs" Inherits="MyControl" %> 
     <asp:Button ID="btn" runat="server" Text="My button" OnClick="btn_Click" /> 

    public partial class MyControl : CacheSubstitutionUserControl 
        public override SubstitutionPageMode PageMode 
                return SubstitutionPageMode.Full; 
        protected void btn_Click(object sender, EventArgs e) 
            // do something 
        protected override void Render(HtmlTextWriter writer) 

    Is there anything I'm missing to get the Button_Click event to fire on the first click itself?

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    28 Dec 2009
    Link to this post
    Hello Hamza,

    Thank you for using our services.

    I have tried to reproduce this behavior with a cache substitution user control developed following steps outlined in this blog post, however to no avail. Can you try to subscribe to the click event like this, from code:
    protected void Page_Load(object sender, EventArgs e)
        btn.Click+=new EventHandler(btn_Click);
    protected void btn_Click(object sender, EventArgs e)

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered