Answered by:
"type not found or control is not registered as safe" when programming a Simple Editor Part

Question
-
I am trying to learn how to program a simple editor part for SharePoint. My code is below - but i get a "type not found or control is not registered as safe" error. Do you see anything wrong here?
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
using System.Collections.Generic;
namespace EV
{
public class PhoneLabel : WebPart, IWebEditable
{
protected string m_phone;
[Personalizable(PersonalizationScope.Shared), WebBrowsable(false), WebDisplayName("Phone")
, WebDescription("Phone Number")]public string Phone
{
get { return m_phone; }
set { m_phone = value; }
}
EditorPartCollection IWebEditable.CreateEditorParts()
{ArrayList partsArray = new ArrayList();
PhoneEditor phonePart = new PhoneEditor();
phonePart.ID = this.ID + "_editorPart1";
phonePart.Title = "Phone Number";
phonePart.GroupingText = "(xxx) xxx-xxxx";
partsArray.Add(phonePart);EditorPartCollection parts = new EditorPartCollection(partsArray);
return parts;
}protected override void RenderContents(HtmlTextWriter writer)
{
writer.Write("<p>" + m_phone + "</p>");
}object IWebEditable.WebBrowsableObject
{
get { return this; }
}
}
//editor
public class PhoneEditor : EditorPart
{
TextBox property = null;protected override void CreateChildControls()
{
property = new TextBox();
Controls.Add(property);
}
protected override void RenderContents(HtmlTextWriter writer)
{
property.RenderControl(writer);
writer.Write("<br/>");
}
public override bool ApplyChanges()
{
try
{
((PhoneLabel)WebPartToEdit).Phone = property.Text;
}
catch (Exception x)
{
//messages.Text = x.Message;
}
return true;
}
public override void SyncChanges()
{
try
{
property.Text = ((PhoneLabel)WebPartToEdit).Phone;
}
catch (Exception x)
{
//messages.Text = x.Message;
}
}
}
}- Edited by Mike Walsh FIN Saturday, January 2, 2010 4:07 PM Original title expanded. "Simple Editor part" wasn't really the question which was about 'why am I getting this error code?'
Saturday, January 2, 2010 3:42 PM
Answers
-
> other web parts in this assembly work fine
Are they using the same Namespace? The SafeControl entry says "lady", but the code says "namespace EV".
Mike Smith TechTrainingNotes.blogspot.com- Marked as answer by Aaron Han - MSFT Friday, January 8, 2010 6:15 AM
Saturday, January 2, 2010 10:18 PM -
Yes, it seems like you have used here another namespace if you have copied both from your real project.
You have two possibilities:
1) Change namespace for new web part
2) or add one more SafeControl section to your web.config with new namespace.- Proposed as answer by shridha Tuesday, January 5, 2010 11:18 AM
- Marked as answer by Aaron Han - MSFT Friday, January 8, 2010 6:15 AM
Sunday, January 3, 2010 1:57 AM
All replies
-
Hi,
Did you register your Editor part in Web.config of your web app?
C:\inetpub\wwwroot\wss\VirtualDirectories\<port Number>\web.config
Strong name your assembly and add your editor part as safe control something like this:
<SafeControl Assembly="<assembly name>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<token number>" Namespace="<namespace>" TypeName="*" Safe="True" />
PradeepSaturday, January 2, 2010 4:02 PM -
I did yes indeed.Saturday, January 2, 2010 7:18 PM
-
Then you have done it in wrong web.config or you have forgotten to do IISRESET after change.Saturday, January 2, 2010 7:32 PM
-
Thanks Jevgeni, I'm using a tool to do the deployment, and have had no problem with deployment until trying this custom editor part. You dont see any issue with the code?
Saturday, January 2, 2010 7:44 PM -
This exception means, that control is not registered as safe in web.config for this application, where you are trying to run it.
Just check web.config related to this application and <SafeControls> sectionSaturday, January 2, 2010 7:59 PM -
here's the safe control entry - other web parts in this assembly work fine.
<SafeControl Assembly="myParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=21814fb6adf67bd2" Namespace="lady" TypeName="*" Safe="True" />Saturday, January 2, 2010 9:52 PM -
> other web parts in this assembly work fine
Are they using the same Namespace? The SafeControl entry says "lady", but the code says "namespace EV".
Mike Smith TechTrainingNotes.blogspot.com- Marked as answer by Aaron Han - MSFT Friday, January 8, 2010 6:15 AM
Saturday, January 2, 2010 10:18 PM -
Yes, it seems like you have used here another namespace if you have copied both from your real project.
You have two possibilities:
1) Change namespace for new web part
2) or add one more SafeControl section to your web.config with new namespace.- Proposed as answer by shridha Tuesday, January 5, 2010 11:18 AM
- Marked as answer by Aaron Han - MSFT Friday, January 8, 2010 6:15 AM
Sunday, January 3, 2010 1:57 AM