尝试包装子控件时出现解析器错误

发布于 2024-07-24 23:40:06 字数 855 浏览 2 评论 0原文

我开发了一个继承自 WebControl 的服务器控件,它包装任意数量的子控件并更改它们的输出。 控件类非常简单,只包含RenderContents方法。

以下是如何将其放置在页面上的示例。 (不包括:控件​​命名空间的注册。)这里的目的是 RichImageField 控件的渲染输出将被更改:

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

但是,当我尝试浏览到该页面时,我的控件类中的代码似乎都没有执行,并且我收到了以下错误:

解析器错误消息:类型 'RX.SharePoint.Common.Controls.HideWhitespaceControl' 没有名为的公共财产 'RichImageField'。

我很困惑为什么会出现这个错误。 确实没有名为 RichImageField 的公共属性,因为这不是属性而是子控件!

我的自定义控件正在 SharePoint 发布网站的页面布局中使用,因此我不确定此错误是否来自 SharePoint。 但它看起来像是一个基本的 ASP.NET 错误,那么我错过了什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瘫痪情歌 2024-07-31 23:40:07

也许您需要将 ParseChildren(false)、PersistChildren(true) 属性添加到自定义控件,例如:

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

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

[ParseChildren(false)]
[PersistChildren(true)]
public class YourControl : WebControl
幸福还没到 2024-07-31 23:40:07

您需要重写 AddParsedSubObject(object obj) 方法来处理子元素:

protected override void AddParsedSubObject(object obj)
{
    if (obj is LiteralControl)
    {
        // This is pure HTML or text...
    }
    else if (...)
    {
        // Handle ASP.NET controls...
    }
}

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...
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文