Monday, January 26, 2009

typesThatShouldNotBeExpanded

After having ran into this myself a few times, and for the 5th time being asked by one of my Sitecore friends; I though I would bring this one up. Ever had trouble getting your ASP.NET ListView controls to retain ViewState or do standard Paging? As many of you will know, Sitecore's web.config is a source of endless configuration fun. Sitecore's modular nature is basically founded on this configuration - want to switch something around or change how Sitecore works (at your own risk, usually, but that's ok)? Web.config is the place to go. Many of the settings are self explanatory and well commented, so working out what they do is fairly straight forward. In some cases, they are not, however. If you look through, you will find an element named " typesThatShouldNotBeExpanded". In it you will find two entries:
  • System.Web.UI.WebControls.Repeater
  • System.Web.UI.WebControls.DataList

And while I don't have enough insight into exactly HOW Sitecore ties in to the ASP.NET lifecycle to determine exactly WHY this setting is needed, I can however tell you what happens if you don't fully control it.

Say you have a control, where you drop in an ASP.NET ListView Control. Or a GridView control. They'll appear to work fine at first, but you'll quickly notice that paging and viewstate is acting up a bit on your controls.

The fix for this is easy, and as far as I know this is well known by Sitecore Support. Add your controls to this - almost black magic like - web.config setting, and you're set :-)

So

Add System.Web.UI.WebControls.ListView, and System.Web.UI.WebControls.GridView to this collection if you find paging, viewstate or other things "that normally works" doesn't.

I don't know when this setting was introduced, or even IF there is a reason Sitecore doesn't include these common controls in the list. Maybe there's a negative effect on performance or otherwise.

Searching on the web only produces this one link (searching on SDN, two results but similarly without explanation), and that doesn't tell us anything else than the config setting was apparently introduced in Sitecore 5.3.2 071220.

4 Comments:

Anonymous Paul said...

This is a truly horrible problem! Thanks.

27 January, 2009 10:24  
Anonymous Aboo Bolaky said...

Thanks Mark,
I originally thought that there was something wrong in my code. I had no reason to believe that Sitecore could have had a hand in it. You've obviously enlightened me!!

Well done!!

Many thanks

21 February, 2009 00:35  
Anonymous Paul George said...

You have to wonder why they didn't put a comment in the web.config or at least add GridView and the other affected controls to the TypesThatShouldNotBeExpanded list... ;< Nasty nasty nasty bug.

07 April, 2009 12:04  
Blogger Mark Cassidy said...

Well.. According to information that sits behind the password shield on http://sdn.sitecore.net/SDN5/Forum/ShowPost.aspx?PostID=14956, it's not really a bug. It's more a sideeffect of the way Sitecore hooks into the page lifecycle - something I know almost nothing about as it is not documented and most of the code sits behind obfuscation. Since this is very core functionality to Sitecore I guess this makes perfect sense, to protect rights and patents and so on.

I agree though, a heads-up and perhaps having the most commonly used ASP.NET types added to the list by default would be nice.

07 April, 2009 12:15  

Post a Comment

Links to this post:

Create a Link

 

<< Home