实现母版页后使用 FindControl 出现奇怪的异常

发布于 2024-08-28 07:01:21 字数 821 浏览 3 评论 0原文

我在这里给出了一些简单的转发器代码:

<asp:Repeater ID="ResultsRepeater" runat="server" DataSourceID="ResultsDS">
 <HeaderTemplate>
 <table id="Results" class="data">
  <tr id="Header" runat="server">
   <th>Item</th>
  </tr>
 </table>
 </HeaderTemplate>
</asp:Repeater>

我曾经能够访问转发器来获取所述标头,如下所示:

HtmlTableRow header = ResultsRepeater.Controls[0].Controls[0].FindControl("Header") as HtmlTableRow;

在实现母版页之后,我注意到对 header.InnerText 和 .InnerHtml 的调用抛出异常,具体来说:

'header.InnerHtml' threw an exception of type 'System.NotSupportedException'
'header.InnerText' threw an exception of type 'System.NotSupportedException'

任何人都可以吗?分享一下我到底怎么了?我当然假设母版页导致了这一点,因为这是除了小更新之外我唯一更改的内容(不应以任何方式影响此问题)。

I have some simple repeater code given here:

<asp:Repeater ID="ResultsRepeater" runat="server" DataSourceID="ResultsDS">
 <HeaderTemplate>
 <table id="Results" class="data">
  <tr id="Header" runat="server">
   <th>Item</th>
  </tr>
 </table>
 </HeaderTemplate>
</asp:Repeater>

I used to be able to then access the repeater to get said header, as such:

HtmlTableRow header = ResultsRepeater.Controls[0].Controls[0].FindControl("Header") as HtmlTableRow;

After implementing master pages, I noticed my calls to header.InnerText and .InnerHtml throw exceptions, specifically:

'header.InnerHtml' threw an exception of type 'System.NotSupportedException'
'header.InnerText' threw an exception of type 'System.NotSupportedException'

Can anyone share what's going on with me? I am of course assuming master pages caused this, since it's the only thing I've changed besides minor updates (that should not affect this in any way).

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

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

发布评论

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

评论(2

悍妇囚夫 2024-09-04 07:01:21

HtmlTableRow.InnerHtml 属性的文档是这样说的:“不要读取此属性或为其赋值。否则,将引发 System.NotSupportedException 异常。此属性继承自 HtmlContainerControl 类,不适用于 HtmlTableRow 类”。

看来你不能这样做。

The documentation for the HtmlTableRow.InnerHtml property says this: "Do not read from or assign a value to this property. Otherwise, a System.NotSupportedException exception is thrown. This property is inherited from the HtmlContainerControl class and is not applicable to the HtmlTableRow class."

Looks like you can't do this.

冷︶言冷语的世界 2024-09-04 07:01:21

这不是母版页的问题。 HtmlTableRow的InnerHtml和InnerText属性就是这样设计的,它们会抛出NotSupportedException。以下是 HtmlTableRow 类中定义的 InnerText 属性的实现:-

public override string InnerText
{
    get
    {
        throw new NotSupportedException(SR.GetString("InnerText_not_supported", new object[] { base.GetType().Name }));
    }
    set
    {
        throw new NotSupportedException(SR.GetString("InnerText_not_supported", new object[] { base.GetType().Name }));
    }
}

InnerHtml 属性也是如此。您可能必须重新考虑当前的方法。

Its not the problem with Master Pages. HtmlTableRow's InnerHtml and InnerText properties are designed like that , they will throw NotSupportedException. Following is the implementation of InnerText property as defined in HtmlTableRow class :-

public override string InnerText
{
    get
    {
        throw new NotSupportedException(SR.GetString("InnerText_not_supported", new object[] { base.GetType().Name }));
    }
    set
    {
        throw new NotSupportedException(SR.GetString("InnerText_not_supported", new object[] { base.GetType().Name }));
    }
}

And its the same for InnerHtml property.You might have to rethink on your current approach.

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