Loading

EDITING CUSTOM MODULE DATA - Part 2

Recently I've shared an idea of how you could provide live site users with edit interface for custom module data. As you might know, perfection has no boundaries... This time I want to share some improvement, those will allow you to reuse the same web part for literally any object within your application.

I'm my first post on the related topic I've suggested using UI Form control in order to create/edit custom (or even native) objects within you system. It works perfectly fine with any particular object, but there is a limitation: you have to know what object you are going to work with beforehand. That's good, but not generic enough. So I went further and implemented class agnostic web part.
 
There were two challenges during implementation:

  • Instantiate object knowing just class code name when creating new object
  • Retrieve object data knowing just class code name and ID of an object when updating one
 
In first case ObjectTypeManager and a little bit of .net reflection were really useful.
In second case I knew ObjectQuery is the right path to go, but struggled with finding appropriate methods for data I have. Finally it turned to be really simple.
 
Following is entire code of my custom web part:
 

public partial class CMSWebParts_MyWebParts_EditObject : CMSAbstractWebPart
{
    public string Class
    {
        get
        {
            return ValidationHelper.GetString(GetValue("Class"), "");
        }
        set
        {
            SetValue("Class", value);
        }
    }

    public string Layout
    {
        get
        {
            return ValidationHelper.GetString(GetValue("Layout"), "");
        }
        set
        {
            SetValue("Layout", value);
        }
    }

    protected override void OnInit(EventArgs e)
    {
        var id = -1;
        if (!string.IsNullOrEmpty(Request.QueryString["id"]))
        {
            id = int.Parse(Request.QueryString["id"]);
        }

        var obj = ObjectTypeManager.GetTypeInfo(this.Class);

        BaseInfo bi = null;

        if (id > 0)
        {
            var editObj = new ObjectQuery(this.Class)
                .WhereID(obj.ClassStructureInfo.IDColumn, id)
                .FirstOrDefault();
            bi = (BaseInfo)editObj;
        }
        else
        {
            var newObj = Activator.CreateInstance(obj.InfoType);
            bi = (BaseInfo)newObj;
        }

        EditForm.EditedObject = bi;
        EditForm.Mode = id > 0 ? FormModeEnum.Update : FormModeEnum.Insert;
        EditForm.ObjectSiteID = SiteContext.CurrentSiteID;
        EditForm.ObjectType = this.Class;
        EditForm.MessagesPlaceHolder = new CMS.ExtendedControls.MessagesPlaceHolder();

        EditForm.AlternativeFormName = AlternativeFormInfoProvider.GetAlternativeFormInfo(this.Layout).FormName;
    }

    public override void OnContentLoaded()
    {
        base.OnContentLoaded();
        SetupControl();
    }

    protected void SetupControl()
    {
        if (StopProcessing)
        {
            EditForm.StopProcessing = true;
        }
    }
}


 
This control is generic enough to work with any object you need. Class property allows you to select object class and Layout allows you to specify alternative layout for your form. Also you don't need to adjust your code behind whenever you add new field to the object UI Form will take care about it.

Please, feel free to share your thought, ideas, feedback or experiance on this topic.


Comments
TV Comparisons Chart
Wow, such an awesome post,! This really is actually exciting articles.Look advanced to far added agreeable from you. Thanks for sharing this articles.
2/21/2018 7:48:07 AM

Apple TV Customer Service Number
Our organization has the team of highly experienced members who are always ready to help the users who are facing issues with their Apple TV Customer Service Number. The solutions provided by us are very easy to implement.
<a href="https://www.codecademy.com/techyapple//"> Apple TV Customer Service Number </a>
2/21/2018 6:19:18 AM

soundcloud to mp3
Really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
2/13/2018 2:38:38 PM

Chrome Support
Thanks for making such a cool post which is really very well written. I will be referring a lot of friends about this. Keep blogging!
1/23/2018 6:47:07 AM

Hitachi Printer Support
Nice Blog! thanks for sharing.
1/22/2018 6:37:06 AM

Xbox Customer Service
Xbox will help you troubleshoot whatever problem that is bothering you. While most the problems are all software based. There could be some hardware problems as well.
1/22/2018 5:30:38 AM

Kaspersky Customer service
Very nice post, thanks for sharing this with us. Waiting for other good posts like this from your side.
1/20/2018 7:55:19 AM

Cisco customer service
this post is very informative for me and thanks so much for sharing this post with us
1/6/2018 11:20:11 AM

Bitomax
Thanks for sharing this article.<a href="http://www.bitomax.com/">Digital Currency Services</a>

<a href="http://www.bitomax.com/">Bitcoin Cloud Mining</a>
1/6/2018 7:40:47 AM

Baltazar
I've already commented on some of the REST posts, I found them very useful. I am also glad to have found this article. Got a bit confused in Part 1, but you've clarified it better here. Thanks.
1/4/2018 11:27:36 AM

LINKSYS ROUTER CUSTOMER SUPPORT
amazing post
keep sharing
1/3/2018 6:44:31 AM

Apple Airport Customer Service
I like the above shared article very much as it contains information which is very important to us, thanks for sharing
1/2/2018 12:13:49 PM

kitchen renovation brooklyn
Considering a new kitchen renovation? The kitchen began as a abode to cook, serve banquet and eat. It was a allowance in the abode that served a purpose, abundant like a bedchamber to beddy-bye in or a bath to get dressed in.
12/27/2017 6:50:18 AM

تور تایلند
Nice post. Thank you for the info. Keep it up.
12/23/2017 11:43:54 AM

تور تایلند
Nice post. Thank you for the info. Keep it up.
12/23/2017 11:43:50 AM

Dissertation Proposal Writing Service
We might want to illuminate you I just investigate your site and additionally We think it is truly entrancing and also instructive..
11/25/2017 8:17:06 AM

belkin range
Thanks for sharing great article with us. keep it
11/9/2017 9:29:54 AM

Topbraindumps cisco 200 355
It’s very excellent information and more real facts to provided that post.Thank you for sharing this information.
11/4/2017 4:44:17 AM

waqar mazhar
nice content
10/31/2017 4:25:12 PM

تور تایلند
Nice post. Thank you for the info. Keep it up.
10/25/2017 12:25:55 PM

Web Development Company Los Angeles
I appreciate and thank you for sharing this article
10/24/2017 5:57:54 AM

roblox free robux
You can generate the roblox free robux here as it will allow you full access in playing this game and you will enjoy playing this game from the bottom of your heart.
9/1/2017 11:06:16 AM

Sarki Sozleri
We would like to inform you i simply take a look at your website as well as We think it is really fascinating as well as educational..
8/21/2017 2:12:59 PM

deya
Thanks for share information.
8/1/2017 9:43:38 PM

Examcollection JK0-022 VCE
One way to think of a custom module is like a WordPress widget. A widget is this thing you can add to widget areas in a WordPress theme, only with HubSpot you don't need widget areas, you need flexible columns. Adding a flexible column to a page template takes a few clicks. Creating a new widget area takes custom code and editing core php files. Which would you rather do?

As I mentioned before, some common modules I build for clients are for statistics, case studies, testimonials, etc. Any part of the website that needs to look and function the same across multiple pages but will have different content depending on the page is a prime target to be turned into a custom module.
8/1/2017 6:38:35 AM

MAHRESULT.NIC.IN
The Maharashtra State Board of Technical Education (MSBTE) declared the results for the MSBTE Summer Diploma examinations on Thursday. The candidates can check their grades on the official website msbte.com. As has been observed over the course of the past few weeks, the dates and times of result announcements have been frequently changed. The information above has not been independently verified. However, this article will continue to be updated to reflect official updates as and when they come in.
6/11/2017 9:48:12 PM

facetime for windows
facetime for windows
6/5/2017 11:59:39 AM

facetime for android
facetime for android
6/2/2017 11:20:03 AM

cbseresults.nic.in
The wait of students is finally over as the Central Board of Secondary Education has announced the CBSE class 10th results. The students can check their results through the official websites of the CBSE Board.
5/17/2017 1:58:21 AM

up results nic in
The results for the Class 10th and Class 12th annual examination of the Uttar Pradesh Board will be announced in May.
5/11/2017 8:53:43 AM

videoder dowload
Videoder is an android app that lets you download music and videos from youtube, facebook, instagram, vimeo, dailymotion etc for free.
4/7/2017 9:36:07 AM

Magnus
I'm trying to implement your code... it displays the fields from the class just fine... but when i click the submit button i can track that both AfterValidate and BeforeSave is raised. OnValidationFailed is not raised so validation goes fine...
12/9/2016 1:54:38 PM

Daniel
Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way, how could we communicate?
12/1/2016 7:15:09 AM

John
This really is actually fascinating, That you are a quite specialist blogger. Ive joined your rss feed and sit up for looking for more of your excellent post. Also, I have shared your web site in my social networks!
10/26/2016 9:40:54 AM

 Security code