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.
We have demonstrated in the previous two articles how one can add a new child view to a View and then how one can remove the child view from a View. In this article, we will not learn anything new. All we are going to do is combine the two approaches in order to replace an existing child View with another one.
In order to replace a child view with another child view you will need to complete following steps:
Every time a News Item is being edited (and saved) we will check if the title of the News Item contains word “dirty”. If so, we will redirect user to the website teaching people manners. This is obviously, rather absurd implementation; however it demonstrates a lot when it comes to the capabilities of the new backend architecture.
The following steps will outline how to complete our sample task:
using Telerik.News.WebControls.Admin; |
using System.Web; |
public class CustomNewsItemEditView : NewsItemEdit |
{ |
public override System.Type LocalizationAssemblyInfo |
{ |
get |
{ |
return typeof(NewsItemEdit); |
} |
set |
{ |
base.LocalizationAssemblyInfo = value; |
} |
} |
public override System.Type AssemblyInfo |
{ |
get |
{ |
return typeof(NewsItemEdit); |
} |
set |
{ |
base.AssemblyInfo = value; |
} |
} |
protected override void SaveContent() |
{ |
// check the title for word dirty with ridiculously flawed approached |
if(base.ContentName.Text.ToLower().Contains("dirty")) |
HttpContext.Current.Response.Redirect("http://www.wikihow.com/Be-Polite"); |
base.SaveContent(); |
} |
} |
<viewSettings hostType="Telerik.News.WebControls.Admin.NewsItemsView, Telerik.News"> |
<views> |
<remove name="NewsItemEdit"></remove> |
<add name="NewsItemEdit" viewType="CustomNewsItemEditView, App_Code"></add> |
</views> |
</viewSettings> |
*** IMPORTANT ***
Every time you modify ControlsConfig file it is necessary to restart the application in order for the changes to be applied. While there are numerous ways to restart an application, here are few handy ones - you can restart the IIS server, resave web.config file (e.g. open web.config file, press space, press backspace, save config.file), resave global.asax file (e.g. open global.asax file, press space, press backspace, save global.asax file)…
*** END IMPORTANT ***
With this we have finished our task and you can run the website to give it a try. This sample is also the last article in the topic regarding Controls Config file.
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.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.