Tuesday, July 04, 2006

Problem with DataTreeview & DataContext in a portlet

If you've ever tried writing a portlet containing a DataTreeview & DataContext with the normal DefaultPortletWindow control you've probably noticed that it doesn't work all that well (surely will be fixed in a later release we hope). The problem is that you when you try to expand a node in the DataTreeview you get an error saying DataContext ”” not found. (Method: Sitecore.Web.UI:HtmlControls.Treeview.Toggle(String id)). For anyone that has actually been affected by this issue or will be in the future, there are two ways to address this issue, either programmatically or via a work-around. The programmatical approach for this by issue would be to implement all of the code relating to the DataContext and DataTreeview and, for ex, adding it to a Border control or similar in your C# code. This solution though isn't that friendly to use again in another portlet since it involves you writing all the code for yourself. The work-around is a lot more user-friendly and a solution you might want to adapt instead of writing the same code over and over again each time. In this case, all you have to do is copy the PortletWindow control, rename the control to something else, like myPortletWindow, and save it with a new name where your custom controls are located. After that, apply the new window control to your portlet xml layout replacing the standard one, and save. So, step by step: 1 – Open PortletWindow control (located at \sitecore\shell\Controls\Portal\Portlet window.xml) 2 – Change the name of the control to something else (in this case myPortletWindow) 3 – Save it somewhere (in this case I’m saving the controls under \sitecore modules\Shell\Example\Controls) 4 – Apply the new window control to the portlet xml layout that you had trouble with and save it Once you've done this you can use this window control instead of the default control without further need to manage it programmatically.

No comments: