2012-12-14 39 views
0

我創建了一個Sitefinity小部件,其中只包含iframe。Sitefinity小部件對象引用未設置爲對象的實例

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

在widget的Page_Load中我TRIE訪問服務器端iframe的任何屬性,但我總是得到「不設置到對象的實例對象引用」。

這裏是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; 
      } 
     } 
} 

最近,我從網站到Web應用程序變更項目,但是這並沒有看起來以任何方式影響項目。

除此之外,我不明白爲什麼這個異常不斷拋出,無論我做什麼。

其他人都知道問題可能是什麼?

感謝, 雅克

回答

0

這可能不是取決於你所創建控件的類型的工作。它可能適用於普通的用戶控件,但不適用於自定義控件。

如果您遵循sitefinity文檔,則可以從SimpleView繼承。然後,您可以訪問輔助方法來從模板中檢索控件。因此,而不是這樣的:

ApplicationIFrame.Attributes["src"] = FrameSourceUrl; 

你可以這樣做:

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