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

发布于 2024-10-16 18:05:32 字数 2860 浏览 4 评论 0原文

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

我在 Web 部件上添加属性后出现此错误。当我删除该属性时,Web 部件正在工作,但是当我将其添加回来时,出现了错误。

这是我在代码中添加的属性。

    /// <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>"));
    }

下面是错误页面的捕获屏幕..

在此处输入图像描述

我希望有人可以帮助我解决我的问题。先感谢您!

Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe.

This error comes out after I added a propety on my webpart. When I removed the property the webpart is working but when I added it back the error came out.

Here is the property that I added on my code.

    /// <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; }
    }

This is the method where I consumed my property.. although I'm sure that this does not affect my webpart because I commented this method at the moment...

    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>"));
    }

Below is the captured screen of the error page..

enter image description here

I hope somebody out there could help me solve my problem. Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温馨耳语 2024-10-23 18:05:32

我认为 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 日志以获取更完整的错误信息。

I think Furqan is on the right track. What is the namespace of your control and what does the Assembly element look like in your manifest.xml? Here is what the Assembly element should look like:

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

The namespace in the SafeControl element must match the namespace of your web part. You can use Reflector to get the four part name of your DLL.

If all of that is correct, then the displayed error is sending you down the wrong path. Try opening the web part in the Web Part Gallery and/or check the SharePoint logs for more complete error information.

静若繁花 2024-10-23 18:05:32

我意识到这个问题与 wspbuilder 有关,但我不太确定。大多数情况下,当我重建项目并复制到 GAC 时,我都会遇到这种错误。我发现,如果我重建项目,然后单击复制到 gac,然后单击回收应用程序池...两次或三次,此错误就会消失,我可以回去工作。很烦人,但不知怎的,它对我有用。 :)

I realized that this issue has something to do with the wspbuilder but I am not really sure of that. I just encounter this kind of error most of the time when I rebuild the project and do the copy to GAC thing. I find out that if I rebuild the project then click on the copy to gac and click on the recycle app pools...twice or thrice, this error is gone and there I can go back to work. So annoying but somehow it works for me. :)

回忆那么伤 2024-10-23 18:05:32

尝试使用以下代码

    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; }
    }

try using the following code

    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; }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文