2011-02-10 34 views
0

錯誤:無法顯示或導入此頁面上的Web部件或Web窗體控件。找不到類型,或者未註冊爲安全類型。Web部件錯誤:無法顯示或導入此頁面上的Web部件或Web窗體控件

在我的web部件上添加了一個propety後出現此錯誤。當我刪除該屬性的webpart工作,但當我加回來的錯誤出來了。

以下是我在代碼中添加的屬性。

/// <summary> 
    /// Property that contains the maximum number of answers allowed in the question 
    /// </summary> 
    /// <value>The number of answers allowed</value> 

    const int default_intPollMaxAnswers = 2; 
    private int intPollMaxAnswer = default_intPollMaxAnswers; 
    [WebBrowsable(true)] 
    [WebDisplayName("Maximum No. of Answers")] 
    [WebDescription("Total no. of answers")] 
    [Category("Poll settings")] 
    [Personalizable(PersonalizationScope.Shared)] 
    [DefaultValue(default_intPollMaxAnswers)] 
    public int SPUserPollMaxAnswer 
    { 
     get { return intPollMaxAnswer; } 
     set { intPollMaxAnswer = value; } 
    } 

這是我消費我的財產。雖然我敢肯定,這不會影響我的WebPart,因爲我評論目前這一方法的方法...

private void InsertPollModalDialogForm() 
    { 
     this.Controls.Add(new LiteralControl(@"<div id=""divPollDialogForm"" title=""User Poll"" style=""font-size:8pt; display:none;"">")); 
     this.Controls.Add(new LiteralControl(@"<table border=""0"" style=""width: 345px; height: 73px"">")); 
     this.Controls.Add(new LiteralControl(@"<tr>")); 
     this.Controls.Add(new LiteralControl(@"<td style=""width: 122px"">Poll title </td>")); 
     this.Controls.Add(new LiteralControl(@"<td><textarea title=""What is your poll question?"" class=""text ui-widget-content ui-corner-all"" style=""width:100%;"" id=""txtPollQuestion"" rows=""2"" cols=""4""/></td>")); 
     this.Controls.Add(new LiteralControl(@"</tr>")); 
     for (int intCountAnswers = 1; intCountAnswers < intPollMaxAnswer; intCountAnswers++) 
     { 
      this.Controls.Add(new LiteralControl(@"<tr>")); 
      this.Controls.Add(new LiteralControl(@"<td style=""width: 122px; height: 43px"" valign=""top"">Answer </td>")); 
      this.Controls.Add(new LiteralControl(
        string.Format(@"<td style=""height: 43px""><input type=""text"" 
            class=""clsAnswers"" id=""txtAnswer{0}"" 
            style=""width:200px""/></td>", 
            intCountAnswers 
      ))); 
      this.Controls.Add(new LiteralControl(@"</tr>")); 
     } 
     this.Controls.Add(new LiteralControl(@"<tr><td colspan=""2""><br /></td></tr>")); 
     this.Controls.Add(new LiteralControl(@"</table>")); 
     this.Controls.Add(new LiteralControl(@"</div>")); 
    } 

下面是錯誤頁面的捕獲畫面..

enter image description here

我希望有人在那裏可以幫助我解決我的問題。先謝謝你!

+0

你可以提供代碼,你消耗這個屬性值,因爲他們在你的財產聲明沒有問題 – 2011-02-10 07:09:09

+0

@Ashutosh:嗨,我已經編輯我的文章。希望能幫助到你。感謝:) – 2011-02-10 07:37:27

回答

0

我意識到這個問題與wspbuilder有關,但我不確定這一點。當我重建項目並複製到GAC中時,我大部分時間都遇到這種錯誤。我發現,如果我重建項目,然後點擊複製到gac,然後單擊回收應用程序池...兩次或三次,這個錯誤消失了,我可以回去工作。這很煩人,但不知何故,它適用於我。 :)

0

如果您將屬性重命名爲某個沒有「SPUser」的屬性,會發生什麼情況?

0

嘗試使用下面的代碼

const int default_intPollMaxAnswers = 2; 
    private int intPollMaxAnswer = default_intPollMaxAnswers; 

    [Personalizable(PersonalizationScope.Shared), 
    WebBrowsable(true), 
    FriendlyNameAttribute("Connection String"), 
    SPWebCategoryName("Custom Properties")] 
    public int SPUserPollMaxAnswer 
    { 
     get { return intPollMaxAnswer; } 
     set { intPollMaxAnswer = value; } 
    } 
1

我覺得Furqan是在正確的軌道上。什麼是您的控件的名稱空間,Assembly元素在manifest.xml中的外觀是什麼?以下是組件元素的外觀:

<Assembly Location="MyProject.dll" DeploymentTarget="GlobalAssemblyCache"> 
    <SafeControls> 
    <SafeControl 
     Assembly="MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0000000000000000" 
     Namespace="MyProject.UI.WebControls.WebParts" 
     TypeName="*" 
     Safe="True" /> 
    </SafeControls> 
</Assembly> 

SafeControl元素中的名稱空間必須與您的Web部件的名稱空間相匹配。您可以使用Reflector來獲取DLL的四個部分名稱。

如果所有這些都是正確的,那麼顯示的錯誤就是將錯誤的路徑發送給您。嘗試打開W​​eb部件庫中的Web部件和/或檢查SharePoint日誌以獲取更完整的錯誤信息。

相關問題