How do I insert custom @ Register tags into the aspx file from my custom control

Platform: ASP.NET|Category: Custom Controls

In the custom control’s custom designer’s Initialize override, do something like this:

[C#]
public override void Initialize(IComponent component)
{

 	base.Initialize (component);

	IDesignerHost host = component.Site.Container as IDesignerHost;
 	IDesigner designer = host.GetDesigner(host.RootComponent);

 	// Calling GetHTMLFromWebControlTool with the following custom toolboxitem will insert the
 	// Register directives for the type associated with that .
 	MethodInfo mi = designer.GetType.GetMethod('GetHTMLFromWebControlTool', BindingFlags.NonPublic | BindingFlags.Instance);
 	if(mi != null)
	{
  		// DependantType is a custom type defined in DependantAssembly.dll
  		mi.Invoke(designer, new object[]{new WebControlToolboxItem(typeof(SomeNamespace.DependantType))});
 	}
}

Then when the user drags and drops the item from the toolbox, besides the default @ register entry it makes, it will also make an entry like this: <%@ Register TagPrefix=’cc1′ Namespace=’SomeNamespace’ Assembly=’DependantAssembly, Version=2.0.0.1, Culture=neutral, PublicKeyToken=3d6dfsd1fdsd44c89′ %>

The assembly will not be strong named in the above tag if it’s not in the GAC.