R – Add Custom Control in Asp.net

asp.netcontrolssharepoint

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

Best Answer

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.