5

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?

1
  • 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? Jan 31, 2012 at 19:54

5 Answers 5

1

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

1

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

1

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

1

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

0

Did you activate the feature that activates the Delegate Control?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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