More in this section

Forums / Developing with Sitefinity / Page cannot be null in Edit mode

Page cannot be null in Edit mode

3 posts, 0 answered
  1. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    10 May 2010
    Link to this post
    Hello Sitefinity team

    I am busy with the devlopment of a custom control. In this custom control I make use of a template (web user control ascx). The overriden property LayoutTemplateName points to this ascx file.

    Now I have defined the RadWindowManager control in this ascx template. Still everything works fine in website/user mode. I can make use of the defined RadWindows without a problem.

    However when I open the page, where the custom control is used, in edit mode (cmspagemode=edit), the control comes back with the error 'Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.'
    When I remove the RadWindowManager control the error is gone.

    Have you any idea how to remove this error message?

    Kind regards
    Luc Baeten
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    10 May 2010
    Link to this post
    Hello Luc Baeten,

    Thank you for using our services.

    Ajax control need the page object not to be null. However in edit mode the page actually does not exist and you will get this error message. You can go about this error the same way as we do it in our controls. In CreateChildControls or in InitializeControls check if the page exists and then create the child controls, else just add a simple label saying that the control cannot be viewed in edit mode:
    protected override void InitializeControls(Control controlContainer)
    {
        if (Page == null || DesignMode)
        {
            Label noDesignModeLabel = new Label();
            noDesignModeLabel.Text = "The control cannot be viewed in design mode";
            this.EventsSchedule.Visible = false;
            this.Controls.Add(noDesignModeLabel);
        }
        else
        {
            //add other logic here
        }
    }

    So in your case you should add the control to the controls collection only if the page is not null.

    Best wishes,
    Radoslav Georgiev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    10 May 2010
    Link to this post
    hello Radoslav,

    Thank you very much for the quick response. This helped me to solve the problem.

    Kind regards
    Luc
Register for webinar
3 posts, 0 answered