实现母版页后使用 FindControl 出现奇怪的异常
我在这里给出了一些简单的转发器代码:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
这不是母版页的问题。 HtmlTableRow的InnerHtml和InnerText属性就是这样设计的,它们会抛出NotSupportedException。以下是 HtmlTableRow 类中定义的 InnerText 属性的实现:-
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 :-
And its the same for InnerHtml property.You might have to rethink on your current approach.