Editing Custom Module Data on the Live Site

#Custom software development #Kentico development #.NET #Kentico Kontent

SHARE

 
Despite the fact that Kentico provides nice interface for managing data inside of the custom modules, sometimes there is a need to provide user to do so on the live site. There are appropriate web parts for editing pages, working with online forms or custom tables, but I couldn't find any control that provides similar functionality for custom module class. In this post I want to share with you solution I found.

 

Problem

Let's consider a situation when you need to expose editing interface for custom module class (or any other type of object) on the live site. There might be a couple of good reasons for doing this, for example there is a role responsible for management of data for a single class, so there is no need to overwhelm that role by exposing Kentico Admin interface, as it could be confusing for non-technical staff.
 

Solution

You can always implement you custom control that will allow you to create/update some object within a system. But what if you need to add a new field at some point of time?! - Yes, you'll need to update you custom control accordingly and promote it through all environments. It is not that exciting when we are talking about adding a single field.

So what would be the approach to take? UI Form will solve that problem. This is a great control that can work with any class as well as it knows how to handle alternative forms. There are just a couple of simple steps you need to take in order to build edit form for your object:

1. Create custom user control or web part

2. Add UI Form to it:
 

<cms:uiform runat="server" id="EditForm" islivesite="true">

</cms:uiform>


3. Initialize vital properties for UI Form:
 

EditForm.EditedObject = myObj; 

EditForm.Mode = CMS.ExtendedControls.FormModeEnum.Update;

EditForm.ObjectSiteID = SiteContext.CurrentSiteID;

EditForm.ObjectType = "className";

EditForm.AlternativeFormName = "formCodeName";



In case you need to create new record substitute firs two lines of code with the following:
 

EditForm.EditedObject = new MyCustomClass(); 

EditForm.Mode = CMS.ExtendedControls.FormModeEnum.Insert;



You'll have to place this code in init or load handlers of your control/web part

4. Add some logic that will alert user if operation has been completed successfully or there was some error

5. Make sure to add security checks, so only authorized users can make changes
 

Conclusion

Now you have a flexible control that you can change without code modifications, but adjusting alternative form or adding new field. It is always easier to reuse something existing and well tested instead of inventing something new. This is a case when less is more!
 

Author

Check other articles

Bitsorchestra
5 5

What our clients say

Bits Orchestra team are outstanding developers‚Äč. They listen carefully to our business needs and easily turns our business objectives into a well thought out and executed development effort. Roman is very bright and definitely the most capable developer that has worked on our site. He is not only a Kentico expert but has successfully tackled other complicated development assignments demonstrating expertise in both front and backend development. Roman takes initiative to suggest enhancements that make site maintenance easier while improving the customer experience. The team is very responsive to our work requests and has great follow up. They have also worked very business partners and this has reflected positively on our company. Roman is a true partner for us and a tremendous asset to our organization. We will continue to work with them and would highly recommend Roman and his team for your development needs. He and his team will exceed your expectations!
 Alan Lehmann
Alan Lehmann
President at In energy sector

What our clients say

The Bits Orchestra team does excellent work. They are always available and I appreciate our frequent calls and screen-shares together. Their dedication to the projects and knowledge of Kentico is outstanding. They truly care about the quality of their work, and became a part of our team easily!
Shena Lowe
Shena Lowe
Managing Partner at Consensus Interactive

What our clients say

We hired Roman for a Kentico analysis project and have been very satisfied. He is very skilled and professional. We are looking to hire him and his team again on future projects.
Sylvain Audet
Sylvain Audet
CEO at MyDevPartner.com

What our clients say

Roman and team have taken over an existing Kentico EMS site for a large US Oil Company. So far, they have handled every single request that we have thrown at them and these were diverse, challenging, often bespoke, usually urgent and almost daily, over the last 11 months. Their work is of an extremely high quality, they are capable, quick and we have great confidence in the support that we are getting.
Jon Hollis
Jon Hollis
Head of Web Development at confidential

What our clients say

Bits Orchestra team was very helpful, they had a good understanding of the brief and deep knowledge of the system. They were always keen to provide advice and recommendations that benefit the project substantially.
Ramon Lapenta
Ramon Lapenta
Senior Front End Developer at Cyber-Duck Ltd