Deliver superior customer experiences with an AI-driven platform for creating and deploying cognitive chatbots
Deliver Awesome UI with the most complete toolboxes for .NET, Web and Mobile development
Automate UI, load and performance testing for web, desktop and mobile
A complete cloud platform for an app or your entire digital business
Detect and predict anomalies by automating machine learning to achieve higher asset uptime and maximized yield
Automate decision processes with a no-code business rules engine
Optimize data integration with high-performance connectivity
Connect to any cloud or on-premises data source using a standard interface
Build engaging multi-channel web and digital experiences with intuitive web content management
Personalize and optimize the customer experience across digital touchpoints
Build, protect and deploy apps across any platform and mobile device
Rapidly develop, manage and deploy business apps, delivered as SaaS in the cloud
The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
As you can see all you need to do in order to create a new View is to create a new class and inherit from ViewModeControl or ViewModeUserControl in which case we will create a new user control.
As it becomes apparent now, ViewModeControl and ViewModeUserControl classes are generic and we need to specify generic argument when inheriting from them. The argument we are specifying here is the host of the View. You can think of host as a parent view, the view to which this view is a subview.
We see that in Sample 1, host view is ContactsControlPanel View, while in the Sample 2, host or parent is ContactsView View. *** BEGIN NOTE ***
You may have read that Views should be host ambivalent, meaning that they could be plugged anywhere in the hierarchy of views. Views in Sample 1 and Sample 2 are not host ambivalent. View in Sample 1 always needs to be hosted by View of type ContactsControlPanel, while View in Sample 2 must always be hosted by View of type ContactsView.
To make View host ambivalent we can define it as follows: SAMPLE 3: Creating host ambivalent views
By taking this approach, we have enabled our View to be hosted by any class that inherits from Control class, and in effect this means by any other ViewModeControl or ViewModeUserControl classes. We have made our View host ambivalent.
Sometimes it makes sense to design Views that can be hosted by only particular type of a View (e.g. CommentsEdit must be hosted by CommentsView), while sometimes it is better to make host ambivalent Views (e.g. CommentsView should be able to work with different types of Views, so that we can reuse it in Control Panel classes for News, Events, Blogs and so on). *** END NOTE ***
So as you can see, all you need to do in order to instantiate a template in a view is to override the LayoutTemplatePath property and ViewModeControl will do the rest of work for you (including adding the controls).
If your views are not part of the website, but rather a class library you may want to embed your templates together with the project. Embedding templates is really simple just as is instantiating user interface from them. To embed your template within a class library, you need to copy the file to the project and set it’s Build Action to “Embedded Resources.
SAMPLE 5: Instantiating embedded template in a View
This time we are overriding LayoutTemplateName property and simply returning the name of resource which holds our embedded template.
*** BEGIN NOTE ***
ViewModeControl classes have a built in system for mapping your embedded templates to an external one, so you do not need to worry about that. More on this subject in articles about the ControlConfig configuration file.
*** END NOTE ***
We can also add controls programmatically to our Views and to do so we need to override the InitializeControls method:
*** BEGIN WARNING ***
Do not override CreateChildControls method directly. For the purposes of your development use InitializeControls which will be called at the opportune time for your controls to be initialized.
*** END WARNING ***
SAMPLE 6: Adding controls programmatically to the collection of child controls
The neat thing about the new architecture is that ViewModeControl base class is taking care of all this plumbing for you. Let us see how all this works with the new architecture.
SAMPLE 7: Accessing controls defined in templates
There are several important things in the sample above. Notice that we have overridden InitializeControls method and changed the text property of the MyViewButton property. Then we take a look and see how have we implemented MyViewButton property. All we did is called GetControl function of the Container object (that has been initialized with template for us on the base class) and specified what type of control we are looking for, specified the ID of the control that we wish to return and finally set true for the isRequiredControl argument.
ViewModeControl base class will do everything else for us.
Another important thing to note here is that MyViewButton is a virtual property of our view. Since we have specified to GetControl function that control is required an exception will be thrown if the control is not present in the template. Let us suppose now that we want to reuse this view, but we don’t need the MyViewButton control anymore. We have the ability to simply override MyViewButton property in our derived class as follows:
SAMPLE 8: Changing the control requirement
Alternatively, we could return just null.
The difference is pretty much what you would expect. We do not specify the generic type of the view, but rather we have another argument where we specify the virtual path of the user control which implements the view.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.