Question

I have developed a server control inherited from WebControl that wraps any number of child controls and changes their output. The control class is very simple and only contains the RenderContents method.

Here is an example of how it has been placed on the page. (Not included: registration of control namespaces.) The intention here is that the rendered output from the RichImageField control will be changed:

<RX:HideWhitespaceControl runat="server">
    <PublishingWebControls:RichImageField
        FieldName="PublishingPageImage"
        runat="server"
        id="PageImage">
    </PublishingWebControls:RichImageField>
</RX:HideWhitespaceControl>

However when I try to browse to the page none of the code in my control class appears to execute and I receive the following error:

Parser Error Message: Type 'RX.SharePoint.Common.Controls.HideWhitespaceControl' does not have a public property named 'RichImageField'.

I'm confused about why this error is appearing. There is indeed no public property named RichImageField as this is not a property but rather a child control!

My custom control is being used in a SharePoint publishing site on a page layout so I'm not sure if this error is coming from SharePoint. But it looks like a basic ASP.NET error so what am I missing?

Was it helpful?

Solution

Maybe you need to add the, ParseChildren(false), PersistChildren(true) attributes to your custom control, like:

[ParseChildren(false)]
[PersistChildren(true)]
public class YourControl : WebControl

OTHER TIPS

You need to override the AddParsedSubObject(object obj) method to handle child elements:

protected override void AddParsedSubObject(object obj)
{
    if (obj is LiteralControl)
    {
        // This is pure HTML or text...
    }
    else if (...)
    {
        // Handle ASP.NET controls...
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top