473,378 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Output Caching in UserControl

Hi,

I have a strange problem with a usercontrol on a page. The usercontrol
dispalyes three categories (From a database) when the user clicks a category
they see all the products in a shop for that category, the results are paged
10 to a page and the user can page them.

As this "Category" usercontrol hardly ever changes I wanted to setup up
caching for it. However I realised that when the user clicks a ctageory it
is selected and therfore I would need to cache each instant of the control
varied by the selected category ID. As the category ID is in the querystring
I used varybyparam. Here is my output cache directive for the usercontrol:

<%@ OutputCache Duration="360" varybyparam="CategoryID" shared="true" %>

There is a problem though. When the user selects a category, the correct
one is dispalyed and is shown as selected. Howevere when they click "next
Page" the wrong cahced version of the usercontrol is displayed.

I have stepped through this. I placed a breakpoint in the page load of the
usercontrol. This is what happens:

(When I click on a category a redirect is performed, to the same page but
changing the CategoryID querystring)

1) First page loads - Usercontrol is loaded from DB. (Breakpoint Hit)
2) I click on Category1 - Usercontrol is loaded from DB. (Breakpoint Hit)
3) I click on Category2 - Usercontrol is loaded from DB. (Breakpoint Hit)
4) I click on Category3 - Usercontrol is loaded from DB. (Breakpoint Hit)

2) I click on Category1 - Usercontrol is loaded from CACHE.
3) I click on Category2 - Usercontrol is loaded from CACHE.
4) I click on Category3 - Usercontrol is loaded from CACHE.

5) I click "Next Page". Postback Occurs. Usercontrol is loaded from CACHE.
Wrong cached instance is used though.

It seems as though after a postback the varybyparam is going awol.

Can anybody Help?

PS The usercontol has viewstate disabled, but enabling it makes no diffrence.
Nov 18 '05 #1
8 1936
Hi,
I've seen similar problems myself, but never had the opportunity to
research too far into it. If you can supply me with an accurate repro I may
be able to make some progress.

Andy Mortimer [MS]
Please do not send email directly to this alias. This alias is for
newsgroup purposes only

This posting is provided "AS IS" with no warranties, and confers no rights.
OR if you wish to include a script sample in your post please add "Use of
included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
Nov 18 '05 #2
Do you want code so that you can reproduce this on your client?

If this is what you want I can give this. you can see the action here
http://www.trendytadpoles.co.uk/default.aspx

The user control is the top Category Menu (GIRLS | BOYS | UNISEX). I have
set the duration to 1 for this site. so it seems like it is working when you
look.

When I increase the duration to say 60, when you click on Girls and then
click ion the "Next Page" paging control, the Category "GIRLS" looses its
selection. The page has loaded the cached version of the control where no
category is selected. This cahced version is the version that is created
when the site first loads.
B..M

The URL I gave has the site, but as I said I had to set the duration to 1 so
that it works correctly. The site has not launched yet but I don't want it
to be buggy for my cleitn whilsty she is setting the site up (adding products
etc) When the duration is set to 1 the control is never cached and therefore
works, but I am not getting any performance gains through cacheing.

If you will both find it helpful I can create a test area to show you it in
action when it fails?

I appreciate both your input...
"Andy Mortimer [MS]" wrote:
Hi,
I've seen similar problems myself, but never had the opportunity to
research too far into it. If you can supply me with an accurate repro I may
be able to make some progress.

Andy Mortimer [MS]
Please do not send email directly to this alias. This alias is for
newsgroup purposes only

This posting is provided "AS IS" with no warranties, and confers no rights.
OR if you wish to include a script sample in your post please add "Use of
included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

Nov 18 '05 #3
I'm not sure who your are replying to (both?). I will need to see a small
cut down reproduction of the problem which I can build and use to reproduce
the problem here. Can you cut out everything from that code (it may be
simpler to create a new app) and then put it on an ftp location which I can
download from? Thanks.
Andy

Nov 18 '05 #4
OK I have created a reproduction page to show the error in its full
technicolor!

http://www.trendytadpoles.co.uk/TestArea/CacheTest.aspx

The three links are in one usercontrol. When a link is clicked it will be
disabled, so you can see which link is clicked.

When you do a postback using the button the usercontrol that was cached
first is displayed.

It seems to mess up with Postbacks, when you click each link over and over
you can see it is using the cached instance, only after a postback does it
fail. It loses the varybyparam on postback.

No code is ran when you click the button it is just for a postback.

Any ideas now?
"When you do a postback using the button the usercontrol that was cached
first is displayed" - This is the error!!!!

"Andy Mortimer [MS]" wrote:
I'm not sure who your are replying to (both?). I will need to see a small
cut down reproduction of the problem which I can build and use to reproduce
the problem here. Can you cut out everything from that code (it may be
simpler to create a new app) and then put it on an ftp location which I can
download from? Thanks.
Andy

Nov 18 '05 #5
This is strange indeed. Basically there is no difference between
(a) clicking the postback button and (b) submitting the link url,
right?
But you see "
- (a) is a POST and (b) is a GET.

I wonder what will happen if you can try an ordinary button instead of
a submit button?

Nov 18 '05 #6
This is strange indeed. Basically there is no difference between
(a) clicking the postback button and (b) submitting the link url,
right?
But you see "
- (a) is a POST and (b) is a GET.

I wonder what will happen if you can try an ordinary button instead of
a submit button?

Nov 18 '05 #7
Yes it is strange.....

I will try the normal button tomorrow, just going to bed now :-)

But it will just perform a postback the same won't it? On my LIVE site the
postback occurs through a linkbutton, not a submit button and the same error
occurs, in fact this is where my problem stems from in the first place.

I think you are on the right track with POST and GET. I never thought of
that....... Therefore do you think I need a hidden form element called
CategoryID that I populate in order for the Postback POST to cache
appropriately by param? I'm just thinking that the GET looks at the
querystring for its param and the POST may exclusively look at the FORM,
therefore adding a FORM element may fix the issue..hmmmm I'll try
that.....It means I will have 6 cached instances 3 for the GET and 3 for the
FORM......But that is better than no cache at all....

I'll post my results on here tomorrow...

Thanks for checking back, just knowing other people think it is strange
helps! Its not just me going mad! :-)

I do find it strange how this has not come up on any forums, and I have
looked high and low....surely I can't be the first to try this?!?!?!?

"Elron" wrote:
This is strange indeed. Basically there is no difference between
(a) clicking the postback button and (b) submitting the link url,
right?
But you see "
- (a) is a POST and (b) is a GET.

I wonder what will happen if you can try an ordinary button instead of
a submit button?

Nov 18 '05 #8
Can I get the code so I can build and reproduce here? Thanks

Andy Mortimer [MS]
Please do not send email directly to this alias. This alias is for
newsgroup purposes only

This posting is provided "AS IS" with no warranties, and confers no rights.
OR if you wish to include a script sample in your post please add "Use of
included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

Nov 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Salvador | last post by:
Hi, I have a wierd situation on my website, can anyone help me? Scenario: I have a page that depending what parameter receives loads one usercontrol or other one. Problem: Sometimes when...
0
by: Martin | last post by:
Hi. I had a very frustrating afternoon and evening but I have got it all under control now so all of a sudden I am in a good mood. I want to share some insights on output caching with you lot. ...
10
by: Umut Tezduyar | last post by:
It seems, it is caching it. The following code is an example for it. How can avoid from this. override void OnLoad (sender and eventargs) { Control control = this.LoadControl (path);...
0
by: alex | last post by:
Ok there are two ways to specify output cache settings for the user control. 1) using attributes public class ctlMine : UserControl{} 2) and using @ OutputCache directive.
2
by: Nalaka | last post by:
Hi, I have the following requirement for caching a asp.net 2.0 page. Can some one please tell me if this is possible.... and a some direction would also be wonderful I have a ASP.net 2.0...
0
by: jason | last post by:
hi experts, support.microsoft.com/kb/917072 and http://msdn.microsoft.com/msdnmag/issues/06/07/WebAppFollies/ As pointed out in these articles, users might get session variables belong to...
0
by: filthysock | last post by:
Has anyone figured out the problem posted in the topic "Output Caching in UserControl" ? We have come across the same issue and was wondering if anyone out there has a solution.
6
by: Rolf Welskes | last post by:
Hello, I want to partial cache by using a UserControl. Now I have a file dependency. In msdn I see it is not possible to do it the same way as in a page. The only information is to create a...
2
by: Ken Fine | last post by:
I have a question about ASP.NET output caching. I want to use screen scraping as a temporary hack to pull in some complex Classic ASP-rendered content into some ASP.NET pages: protected String...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.