Sitefinity widget Object reference not set to an instance of an object

610 Views Asked by At

I've created a Sitefinity widget with only and iframe in it.

<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="ApplicationFrame.ascx.cs"
Inherits="MyProject.Web.Ui.Customized.EmbeddedApplications.ApplicationFrame" %>

<iframe runat="server" id="ApplicationIFrame" height="250" width="250" scrolling="no" frameborder="0" seamless="seamless" src=""></iframe>

In the Page_Load of the widget I trie to access any properties of the server side iframe but I always get "Object reference not set to an instance of an object".

Here's the C#

namespace MyProject.Web.Ui.Customized.EmbeddedApplications
{
        [ControlDesigner(typeof(ApplicationFrameDesigner))]
        public partial class ApplicationFrame : System.Web.UI.UserControl
        {
            public string FrameSourceUrl {get;set;}
            public string FrameHeight { get; set; }
            public string FrameWidth { get; set; }
            protected void Page_Load(object sender, EventArgs e)
            {
                //set the values of the iframe to the current properties
                ApplicationIFrame.Attributes["src"] = FrameSourceUrl;
                ApplicationIFrame.Attributes["height"] = FrameHeight;
                ApplicationIFrame.Attributes["width"] = FrameWidth;
            }
        }
} 

I recently change the project from a Website to a Web Application, but that hasn't seemed to impact the project in any way.

Other than that I can't see why this exception keeps being thrown no matter what I do.

Anyone else know what the problem might be?

Thanks, Jacques

1

There are 1 best solutions below

0
Slavo On

This may not work depending on the type of widget you have created. It would probably work for normal User controls, but not custom controls.

If you are following the sitefinity documentation, you can inherit from SimpleView. Then you have access to helper methods for retrieving controls from the template. So instead of this:

ApplicationIFrame.Attributes["src"] = FrameSourceUrl;

You can do this:

this.GetControl<HtmlControl>("ApplicationIFrame", true).Attributes["src"] = FrameSourceUrl;