【问题标题】:Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or importedWeb 部件错误:无法显示或导入此页面上的 Web 部件或 Web 窗体控件
【发布时间】:2011-06-24 16:00:21
【问题描述】:

错误:无法显示或导入此页面上的 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; }
    }

这是我使用我的财产的方法.. 虽然我确信这不会影响我的 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>"));
    }

下面是错误页面的截图..

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

【问题讨论】:

  • 您能否提供使用此属性值的代码,因为它们在您的属性声明中没有问题
  • @Ashutosh:嗨,我已经编辑了我的帖子。希望能帮助到你。谢谢:)
  • 您是否在 web.config 中将您的 webpart 注册为更安全的控件?即''
  • 如果您将属性重命名为其中没有“SPUser”的名称会怎样?
  • 其实属性名完全没有问题...我什至尝试过你的建议,但结果没有任何区别。顺便谢谢。

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


【解决方案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 日志以获取更完整的错误信息。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      尝试使用以下代码

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

      【讨论】:

        猜你喜欢
        • 2012-01-03
        • 2017-10-21
        • 2011-07-22
        • 2011-08-22
        • 2010-11-28
        • 2011-09-12
        • 2010-09-12
        • 2011-03-31
        • 2012-03-16
        相关资源
        最近更新 更多