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
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

uso_cialis
I toss-up prezzo in italia most the cholesterol for cialis prezzo in italia risk often not.
10/5/2017 3:51:29 PM

Geeta Grewal
Hello, Dear, Great Information, Hi Geeta Grewal here belong from Delhi. And I am one of the best models of Delhi. I like this blog post very much. This is really appreciated able and waiting for the next, I am twenty-three years sensual model from Delhi, I am hot deva with the sensual curves and of the sexy figure. For more info visit our your thought and explaining power is too good. Really it's very impressive. I am waiting for another one. Geeta Grewal Delhi Escorts high-profile model. Twenty-three years sensual model. Who is very beautiful. And I am also famous as a Delhi Escort also For more information visit my site.
<a href="https://www.geetagrewal.com/">Escorts In Delhi</a>
<a href="https://www.geetagrewal.com/">independent escorts in delhi</a>
<a href="https://www.geetagrewal.com/">call girls in delhi</a>
<a href="https://www.geetagrewal.com/"> delhi escorts services</a>
<a href="https://www.geetagrewal.com/">delhi escort</a>
<a href="https://www.geetagrewal.com/house-wife-escorts-call-girls.html">Housewife Delhi Escorts</a>
<a href="https://www.geetagrewal.com/college-escorts-call-girls.html">College Girls Delhi Escorts</a>
<a href="https://www.geetagrewal.com/russian-escorts-call-girls.html">Russian Delhi Escorts</a>
<a href="https://www.geetagrewal.com/air-hostess-escorts-call-girls.html">Air-Hostess Delhi Escorts</a>
<a href="https://www.geetagrewal.com/delhi-call-girls-escorts.html">Delhi Call Girls</a>
<a href="https://www.geetagrewal.com/massage-service-in-delhi.html">Massage Service In Delhi </a>
<a href="https://www.geetagrewal.com/hotels-for-escorts-services.html">Hotels For Escorts Service In Delhi</a>
<a href="https://www.geetagrewal.com/hi-profile-escorts-call-girls.html">Hi Profile Delhi Escorts Call Girls</a>
<a href="https://www.geetagrewal.com/independent-escorts-call-girls.html">Independent Delhi Escorts Call Girls</a>
<a href="https://www.geetagrewal.com/karol-bagh-escorts-call-girls.html">Karol Bagh Delhi Escorts</a>
<a href="https://www.geetagrewal.com/pahar-ganj-escorts-call-girls.html">Pahar Ganj Escorts</a>
<a href="https://www.geetagrewal.com/dwarka-escorts-call-girls.html">Dwarka Escorts</a>
<a href="https://www.geetagrewal.com/mahipalpur-escorts-call-girls.html">Mahipalpur Escorts</a>
<a href="https://www.geetagrewal.com/aerocity-escorts-call-girls.html">Aerocity Escorts</a>
<a href="https://www.geetagrewal.com/noida-escorts-call-girls.html">Nodia Escorts</a>
<a href="https://www.geetagrewal.com/ghaziabad-escorts-call-girls.html">Ghaziabad Escorts</a>
<a href="https://www.geetagrewal.com/faridabad-escorts-call-girls.html">Faridabad Escorts</a>
<a href="https://www.geetagrewal.com/gurgaon-escorts-call-girls.html"> Gurgaon Escorts</a>
<a href="https://www.geetagrewal.com/greater-noida-escorts-call-girls.html"> Greater Noida Escorts</a>
9/30/2017 7:32:49 AM

Geeta Grewal
Hello, Dear, Great Information, Hi Geeta Grewal here belong from Delhi. And I am one of the best models of Delhi. I like this blog post very much. This is really appreciated able and waiting for the next, I am twenty-three years sensual model from Delhi, I am hot deva with the sensual curves and of the sexy figure. For more info visit our your thought and explaining power is too good. Really it's very impressive. I am waiting for another one. Geeta Grewal Delhi Escorts high-profile model. Twenty-three years sensual model. Who is very beautiful. And I am also famous as a Delhi Escort also For more information visit my site.
https://www.geetagrewal.com/house-wife-escorts-call-girls.html
https://www.geetagrewal.com/college-escorts-call-girls.html
https://www.geetagrewal.com/russian-escorts-call-girls.html
https://www.geetagrewal.com/air-hostess-escorts-call-girls.html
https://www.geetagrewal.com/delhi-call-girls-escorts.html
https://www.geetagrewal.com/massage-service-in-delhi.html
https://www.geetagrewal.com/hotels-for-escorts-services.html
https://www.geetagrewal.com/hi-profile-escorts-call-girls.html
https://www.geetagrewal.com/independent-escorts-call-girls.html
https://www.geetagrewal.com/karol-bagh-escorts-call-girls.html
https://www.geetagrewal.com/pahar-ganj-escorts-call-girls.html
https://www.geetagrewal.com/dwarka-escorts-call-girls.html
https://www.geetagrewal.com/mahipalpur-escorts-call-girls.html
https://www.geetagrewal.com/aerocity-escorts-call-girls.html
https://www.geetagrewal.com/noida-escorts-call-girls.html
https://www.geetagrewal.com/ghaziabad-escorts-call-girls.html
https://www.geetagrewal.com/faridabad-escorts-call-girls.html
https://www.geetagrewal.com/gurgaon-escorts-call-girls.html
https://www.geetagrewal.com/greater-Noida-escorts-call-girls.html
9/30/2017 7:31:17 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

https://www.couponnx.in/price-check/
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!
6/21/2017 6:35:45 PM

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

essay on time
Thank you so much for having the second part of the module data that is useful for me and help me a lot to complete my project on time. I really appreciate your great sharing and will visit yours again for upcoming projects help.
3/20/2017 12:53:31 PM

examresults.ap.nic.in
Are you waiting for AP Inter Results 2017? You visit the right place to know the information of Intermediate Results
3/19/2017 9:39:05 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