Strange exceptions using FindControl after implementing master pages
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).
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.
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.
精彩评论