Validate widget controls generate warnings

Posted by Community Admin on 04-Aug-2018 21:42

Validate widget controls generate warnings

All Replies

Posted by Community Admin on 14-Jun-2016 00:00

We had been creating pages and adding controls via API in our custom module during 
Install/Upgrade for a while, but in this version when accessing the PageDraft.Controls Collections it shows warnings in the initialization window, although the process continue normally.

In the below code you can see how we try to find a mvc control in a specific page, if it does not exist we add the control. This code is called from module upgrate method.

public class OurCustomeModule : ModuleBase

    public override void Upgrade(Telerik.Sitefinity.Abstractions.SiteInitializer initializer, Version upgradeFrom)
   
            //Try to add custom controls to a page here
   


The thing is a soon as the "Controls" collection is accessed it throws exceptions that appear in the initialization window as seen in the attachments.

 

var pageManager = PageManager.GetManager();
pageManager.Provider.SuppressSecurityChecks = true;
Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy control = new Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy();
control.ControllerName = controllerType.FullName;
var pageNode = pageManager.GetPageNodes().Where(p => p.Id == pageId).SingleOrDefault();
var pageControl = pageManager.CreateControl<PageDraftControl>(control, placeHolder);
           
if (pageNode != null && pageControl != null)
    PageDraft temp = pageManager.EditPage(pageNode.PageId);
    if (temp != null)
    
        PageDraftControl controlfound = null;
        controlfound = temp.Controls.FirstOrDefault(ctrl => ctrl.ObjectType ==   pageControl.ObjectType && ctrl.Caption == pageControl.Caption);
        if (controlfound == null)
        
           pageManager.SetControlDefaultPermissions(pageControl);
           temp.Controls.Add(pageControl);
           temp = pageManager.PagesLifecycle.CheckIn(temp);
           pageManager.PagesLifecycle.Publish(temp);
           pageManager.SaveChanges();
         
   
pageManager.Provider.SuppressSecurityChecks = false;

Thanks

This thread is closed