| Hack to enforce the cache of an XmlDataSource to invalidate |
| Written by percyboy |
| Friday, 30 January 2009 16:00 |
Introduction
We often use the If the data source is static, it works quite well. But, when the data source needs to be dynamic, there seems to be some problems. This article will introduce one such problem and give you a hack solution. SymptomsIf the data source needs to be dynamic, you may choose to:
Obviously, the first way is more limited and only applicable for some special situations. It"s not a good idea to put a lot of data source controls on one form and, more importantly, the count of the data source controls must be a fixed number.
But, what will happen when you change the value of the
Unfortunately, in my test (you may download the samples to see it yourself), I found that, the cache will not be automatically invalidated when you change the value of the Workaround
First, you may choose to change the value of the
Otherwise, if you stick to changing the property of
public static void XmlDataSourceCacheHack(XmlDataSource dataSource)
{
try
{
Type t = typeof(XmlDataSource);
MethodInfo m = t.GetMethod("CreateCacheKey",
BindingFlags.Instance | BindingFlags.NonPublic);
string key = (string)m.Invoke(dataSource, null);
PropertyInfo p = t.GetProperty("Cache",
BindingFlags.Instance | BindingFlags.NonPublic);
object cache = p.GetValue(dataSource, null);
Type t2 = t.Assembly.GetType("System.Web.UI.DataSourceCache");
MethodInfo m2 = t2.GetMethod("Invalidate",
BindingFlags.Instance | BindingFlags.Public);
m2.Invoke(cache, new object[] { key });
}
catch
{
}
}
(It"s sure that " This is just a hack for this problem. I spent more than one day on debugging to find the source of this strange problem. (P.S.: If you find a more perfect way to solve it, avoiding Reflection, do tell me. Thanks!) Thanks for PlamenLeykov
You may surely entirely disable the cache feature of the
But, if your situation is just like mine: the change possibilities are lower than other postback possibilities (for example, the Is it a bug from Microsoft?I"m not sure whether this is a bug from Microsoft, or if it is just applied to the design specification. But, either the implementation is wrong, or the documentation is wrong. Something wrong with this article? Report it
Set as favorite
Bookmark
Email This
Hits: 117 0 Comments
Write comment
You must be logged in to a comment. Please register if you do not have an account yet.
|
| Last Updated on Friday, 06 February 2009 16:00 |
Latest Articles
- AntiHisto
- Thumbnail images in PHP
- Online Dating Websites
- Hack to enforce the cache of an XmlDataSource to invalidate
- AutoSearch SELECT tag
- Nine ASP.NET Site Navigation Problem Solutions: Part 1
- Enhanced rich edit control
- CheckListBox based on ListBox that supports ReadOnly
- Introduction to COM - What It Is and How to Use It.
- Introduction to the Validation Application Block


