views:

546

answers:

4

I am creating a new Panel..

 public class LicensingPanel : Panel
{
     private LinkButton licenseButton;
    ...
}

I am then in the code adding my controls to the Controls property, one of which is a LinkButton.

What I want to be able to do on my Page code behind is the following..

protected override void CreateChildControls()
{
    Controls.Add(new LicensingPanel(this));

    base.CreateChildControls();
}

But I am getting this error message:

Control 'ctl03' of type 'LinkButton' must be placed inside a form tag with runat=server. at System.Web.UI.Page.VerifyRenderingInServerForm(Control control)

The page is a SharePoint page with a master page, it has a Form tag with runat=server.

Any help is greatly received!

Best Regards,

Phill

+4  A: 

Any page with a MasterPage, whether it is in SharePoint or not, is a Content Page. These pages only support content contained in Content controls. Attempting to add an HTML tag or ASP.NET control directly to the page is not supported.

Rob Windsor
A: 

Where on the page is the control of your type LicensingPanel ? This control needs to be inside the form tag.

Rawbert
A: 

I think you should tell us a little bit more about what you want to archive with your code. Where are you trying to add your control?

Flo
A: 

Hello Phill

I think that you need to complete some steps before you can use a certain control inside a MOSS 2007 environment:

  1. You must register your custom controls DLL as safe.
  2. You must register your custom control in the master page in order for the server to recognize the tag.

FOR DLL: <%@ Register TagPrefix="customcontrolname" Namespace="MyCustomControl" Assembly="MyCustomControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456789abcdefg" %>

FOR ASCX: <%@ Register Src="~/Controls/MyCustomControl.ascx" TagName="MyCustomControl" TagPrefix="customcontrolname" %>

Emilio León
Hi Emilio, Thanks, I am aware of the requirements for SP and controls. I thought I was abled to dynamically add my own controls which according to Rob below can't be done. Regards Phill
Phill Duffy