Code Project

Link Unit

Wednesday, February 03, 2010

When caching is enabled for the XmlDataSource that is control tree it requires a UniqueID that is unique throughout the application

We were using XmlDataSource in code behind and assigning the same to a menu.
XmlDataSource XmlMenu = new XmlDataSource();
This was resulting in "When caching is enabled for the XmlDataSource that is control tree it requires a UniqueID that is unique throughout the application" - Use an ID for XmlDataSource .
The solution for which is specifying the ID of XmlDataSource .
XmlMenu.ID = "Menu1";
Reason:XmlDataSource class internally calls a private method called CreateCacheKey.Now, if you are using XmlDataSource without an ID in Code-Behind. This might throw an exception - "When caching is enabled for the XmlDataSource that is not in the pages control tree it requires a UniqueID that is unique throughout the application." This is due to the absence of the UniqueID ,which is used as part of the caching key.Without ID all instances would try to use same caching key. Setting a distinct ID will resolve the problem.
Post a Comment