Delegate control with class.cs
-
09-12-2019 - |
Question
I searched on google for some clarifications but I didn't find the answers I've been looking for.
I want to deploy a delegate which would perform some custom functionality. That is why with a delegate I want to ship a classe with code, so I did a following:
I added a classe:
public class SomeClassForDelegate: WebControl
{
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.WriteLine("<p>Write some text</p>");
base.Render(writer);
}
}
Basically this classe will write just a text. The reason why I do that is just to test if my classe is being used, normally I'll add totaly difirent functionality.
Then I have a delegate declaration in element.xml:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Id="AdditionalPageHead" ControlAssembly="$SharePoint.Project.AssemblyFullName$" ControlClass="mysolution.SomeClassForDelegate" Sequence="90" />
</Elements>
Which I deploy with a feature.
Everything goes good and well but at the end I don't see the result.
What am I doing wrong?
Update: Solved
The problem was that the webcontrol was not put as safe control. So in an element.xml I added whole folder as a safe place. And it was working.
Thank you for input, especially Dribbel!
Solution
Please check the following:
- Is there any warning in the ULS-logs?
- Is the
sequence
set correctly? - Does adding a breakpoint help (this checks if the code is actually loaded)
- Check if the Control is referenced at all in the page using http://blog.mastykarz.nl/checking-which-delegate-controls-activated-site/ ?
- Is the control registered as safe (check in the web.config after deploying)? Not safe controls will generate an error in the ULS-logs.