0

I followed this article instructional steps from 1 to 7
https://knowledgebase.progress.com/articles/Article/page-appears-blank-to-non-admin-users

Ok, but I have the different case. On that Working page I have placed two layout controls 100%, then I want to get this controls from the code, BUT they are missing.

In the most of the examples in the documentation and knowledge base, they show the following code lines to access that layout controls:

var layoutControlOnPage = pageData.Controls
                .FirstOrDefault(c => c.ObjectType == typeof(LayoutControl).FullName);

BUT in my case, layoutControlOnPage is always NULL. I cannot access any of the Layout controls. The code above is executed from .aspx web form page.

Here are some resources:
https://docs.sitefinity.com/overview-create-pages/for-developers-adding-layout-controls-to-pages-and-page-templates
https://knowledgebase.progress.com/articles/Article/get-placeholders-of-feather-grid-layout-controls

Is it that because the page is without page-template (The page template is set to Empty (start from scratch))?

I post this question here because I hope someone to help me. In the Sitefinity forums, I wouldn't receive any help.

I will try this in another project and will update this soon

Update:
I have tested the same code on another sitefinity project and I am able to access the the layout controls from the code.

Any Ideas how to access in the layout controls and what prevents me to access them?

mihkov
  • 1,171
  • 13
  • 37

2 Answers2

0

I just created a new page without template and dragged one content block and two 100% layout controls. Now I can access them and the following code returns the correct controls as I expected.

var layoutControlOnPage = pageData.Controls
            .FirstOrDefault(c => c.ObjectType == typeof(LayoutControl).FullName);

I don't know what is causing the issue with the previous page.

mihkov
  • 1,171
  • 13
  • 37
0

The issue probably is that that control is nested within another page control. You will want to try and use this recursive method to find the page control.

https://stackoverflow.com/a/253962/2148567

Method from SO answer:

public static IEnumerable<Control> GetAllControls(this Control parent)
{
    foreach (Control control in parent.Controls)
    {
        yield return control;
        foreach(Control descendant in control.GetAllControls())
        {
            yield return descendant;
        }
    }
}

Usage

var checkBoxes = this.GetAllControls()
                     .OfType<CheckBox>()
                     .TakeWhile<CheckBox>(cb => cb.Checked);
Jon R.
  • 977
  • 6
  • 12
  • Thanks for the reply. I am searching for a layout control. And it can be nested only inside another layout control. So I've tried to nest two layout controls and I was able to access them. `pageDraft.Controls.Count` was 2. I cannot reproduce this in another sitefinity project. I had a discussion with the support team and they explained me another possible reason for that issue: to the related layout control was added permission for content control. – mihkov Oct 10 '17 at 14:53