Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created a simple project to Customize a Delegate Control in SharePoint 2010 such as in msdn article (http://msdn.microsoft.com/en-us/library/ms470880.aspx).

Source code: Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
namespace ShowRibbon
{
    class ShowRibbonControl : WebControl
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            string helloAlert = "alert('Hello, world!');";
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "popup", helloAlert, true);

        }
    }

}

Elements.xml:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control Id="AdditionalPageHead"
        Sequence="99"
        ControlAssembly="$SharePoint.Project.AssemblyFullName$"
        ControlClass="ShowRibbon.ShowRibbonControl"/>
</Elements>

I add SafeControl to Empty Element with Elements.xml, but when I run my solution and set breakpoint in OnLoad method, it is not reached. What may be the reason?

share|improve this question
2  
I may be pointing at the obvious, but have you made sure you have attached the debugger successfully and there is no issue with source code not matching the assembly loaded? Have you enabled tracing and looked at the Control Tree? Has your control been loaded? Has the feature been successfully activated? –  Alexey Krasheninnikov Jan 31 '12 at 19:54
add comment

5 Answers 5

I show you my custom search small input box. These is my Elements.xml:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control  Id="SmallSearchInputBox"
    Sequence="25"
    ControlSrc ="~/_controltemplates/Piaggio.Dealer.Portal/SmallSearchInputBoxDelegateControl.ascx">
  </Control>
</Elements>

and these is part of my ascx control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SmallSearchInputBoxDelegateControl.ascx.cs"
Inherits="the.namespace.goes.here.classSmallSearchInputBoxDelegateControl" %>

that's works perfectly

look at this link: http://salvatoredifaziosharepoint.blogspot.com/2012/02/delegate-controls-small-search-input.html

share|improve this answer
add comment

Please check your web.config to see if your SafeControl entry is really inserted and specifies the correct assembly and class. I didn't understand from your description what you did to add it. A missing or incorrect SafeControl entry will most likely be the cause of the control not being used. BTW, if this is the case, you can also see it in the ULS log. Kind regards, Matthias

share|improve this answer
add comment

Make your ShowRibbonControl class a public class. That will make the difference and it will start working and will hit to the OnLoad method.

share|improve this answer
add comment

If you are not seeing any exception on site load then I think you control is working fine, remove the dll from GAC / BIN and see it shoulf throw an error.

Sometimes this.Page.ClientScript.RegisterClientScriptBlock doesn't work in Server control, please try using this.Page.ClientScript.RegisterStartupScript instead.

Also, see the source code of the page to see whether the script has been added.

Edit : Please check the webconfig, if the namespace has been added under safecontrols

share|improve this answer
add comment

Did you activate the feature that activates the Delegate Control?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.