Web部件错误:无法显示或导入此页面上的Web部件或Web窗体控件

时间:2011-02-10 07:01:17

标签: c# sharepoint-2007 properties web-parts

错误:无法显示或导入此页面上的Web部件或Web窗体控件。无法找到该类型或未注册为安全类型。

我在webpart上添加了一个问题后出现此错误。当我删除该属性时,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; }
    }

这是我消耗财产的方法..虽然我确定这不会影响我的网站部分,因为我此刻评论了此方法......

    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

我希望那里的人可以帮我解决问题。提前谢谢!

4 个答案:

答案 0 :(得分:1)

我认为Furqan走在正确的轨道上。控件的命名空间是什么?在manifest.xml中Assembly组件的外观是什么?这是Assembly元素的样子:

<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的四部分名称。

如果所有这些都是正确的,则显示的错误会向您发送错误的路径。尝试在Web部件库中打开Web部件和/或检查SharePoint日志以获取更完整的错误信息。

答案 1 :(得分:0)

如果您将属性重命名为没有“SPUser”的内容会怎样?

答案 2 :(得分: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; }
    }

答案 3 :(得分:0)

我意识到这个问题与wspbuilder有关,但我并不确定。我在重建项目并将副本复制到GAC时,大多数时候都会遇到这种错误。我发现,如果我重建项目,然后点击副本到gac并点击回收应用程序池...两次或三次,这个错误消失了,我可以回去工作。太烦人但不知何故它对我有用。 :)