|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionWe 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 WorkaroundFirst, 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 PlamenLeykovYou 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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||