Search code examples
c#sharepoint-2007propertiesweb-parts

Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported


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!


Solution

  • 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. :)