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..
I hope somebody out there could help me solve my problem. Thank you in advance!
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.
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. :)
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; }
}
精彩评论