I have a user control shared in many pages on my web site. Because it is created from a complicated database query, I decided to enable fragment caching for it.
<%@ OutputCache Duration="600" VaryByParam="None" Shared="True" %>
This works fine rendering-wise.
However, I also have a textbox and an ImageButton in the same control. When a user enters text in the box and clicks the button, I need the control to do some action. The problem is that with fragment caching enabled for this control, I never see the postback in the control.
On one hand, this makes sense since a cached control is not instantiated, but I would have thought there was some provision to allow standard ASP.NET behaviors to work. I can't find any documentation that mentions any restrictions on control or postback behavior when using fragment caching.
I can think of the following workarounds:
1) Break up the control into smaller sub-user controls so that the textbox and button are in a separate one that is not cached. The problem is that the containing structure of the control (i.e. outer divs) is not cached.
2) While reading from the dabase is already cached, the rendering process is not. Perhaps I can create an in-memory representation of the rendered contents and just output that to a literal and leave the rest alone without caching. Again, this means that the containing structure of the control would not be cached.
Perhaps there is some OutputCache or other setting that would allow me to make this work without coding changes. Any suggestions on workarounds?
Thanks in advance,
Dan