Making UserControls work with the WCSF

Topics: Web Client Software Factory
Nov 8, 2006 at 2:38 AM
I know this has been slightly touched on, but I hope that the UserControl support is coming along nicely in the WCSF. Specifically, I'm using the WCSF code in a testing application and it's working great. (Nice work!!). The current hurdle, though, is that the UserControls never get picked up as modules and thus cannot get WorkItems assigned (they don't seem to go through the same HttpHandler routines). I know you're working on support, so I just wanted to vote for this being something that gets sooner than later attention. Vote +1. :)

For those of you who have turned a UserControl into the same MVP pattern and then realized it didn't work, all you have to do is to add the following 2 lines to an OnInit method within the control itself to hack around it (basically simulating the DI):

  • This assumes that you've already added the standard Presenter properties and have the View/View Interface defined like a normal page for this control.

Presenter = new MyControlViewPresenter();
Presenter.Controller = new MyControlLibrary.Module.ModuleController(new MyControlLibrary.Module.Services.MyServiceAgent());

Realize that the parms into the ModuleController are just the same as the DependencyInjection was going to use anyway. This code is bad - it duplicates objects and is ONLY intended to make the UserControls work within the WCSF framework until the p&p team has a better solution. I did this because I'm assuming that the final structure of the UserControls will be something like the MVP pattern already established. Any inside information on if that assumption is true?

Adam
Nov 9, 2006 at 2:46 PM
i use also many usercontrols and custom controls.

what you can also do, if you need this for the dependency injection is to put that into the page.

so step by step:

.) derrive all aspx pages of one of your classes (e.g. MyPage)
.) in MyPage override the property AddedControl
.) add bevore the base.AddedControl(control, index) the code lines:
------------------------------------
IWebClientApplication application = HttpContext.Current.ApplicationInstance as IWebClientApplication;
ICompositionContainer container = application.RootContainer
CompositionContainer.BuildItem(container.Builder, container.Locator, control);
------------------------------------

this is something like an demo code. i implemented this a little bit different specific for my needs. but i think you know what i mean here. if you want you can also add the module identification here. just look up in the CustomHttpHandler.cs. its pretty simple done currently.
important is, that you leave the line, where the AddedControl base is called in the code. otherwise you get problems.

also this is not an solution for all features of the CompositeWeb, since it does not use the module structure.

hope this helps :-)
christoph
Nov 10, 2006 at 11:59 AM
does anybody know if there will be support for something like the cab smartparts? at the moment the view is implemented as an aspx, but this doesn't make very modular applications. the 'hacks' of you both are nice but not from the team, do they plan on refactoring this? would be nice to see these smartparts interact (ajax :) with eachother like the cab webparts do via their controllers.
i know this is really early, but nonetheless this has to be taken into account someday. oh, and keep up the good work!
Jul 25, 2007 at 2:19 PM
Is WPF solution for the same now.

-- Wali.
Jul 28, 2007 at 9:46 PM
Hi Vip

With the next release of WCSF (and in the current community drops) we are supporting something similar to smart parts by allowing user controls (and master pages) to be views. With this functionality you can have a composite view (Page) that contains many child views (Controls). We do not support any notion of workspaces for actually laying out the controls themselves however, though ASP.NET does provide quite a rich set of layout controls on it's own.

As to the interaction / wiring between child views, we have just published a Composability quick start within the current weekly drop that demonstrates how to use the mediator pattern to have child views that interact with one another. On the subject of AJAX, we are also looking at client-side event brokering which would wire up controls to respond to javascript events.

Regards
Glenn