读取ASP.Net控件的原始项模板标记
我想知道是否可以从repeater控件中读取ItemTemplate的原始标记 考虑下面的中继器:读取ASP.Net控件的原始项模板标记,asp.net,Asp.net,我想知道是否可以从repeater控件中读取ItemTemplate的原始标记 考虑下面的中继器: <asp:Repeater ID="uiReport" runat="server" EnableViewState="False"> <HeaderTemplate> <table border="1"> <thead> <tr>
<asp:Repeater ID="uiReport" runat="server" EnableViewState="False">
<HeaderTemplate>
<table border="1">
<thead>
<tr>
<th>Product</th>
</tr>
</thead>
<tbody>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#((Product)Container.DataItem).ProductName%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</tbody></table>
</FooterTemplate>
</asp:Repeater>
对于本例中的中继器控件,“s”(字符串)参数的值为:
\r\n <tr>\r\n <td>
答案似乎是否定的,没有一种虚拟方法可以用来获取未解析的页面。处理页面/控件解析的方法由密封类和内部方法组成 这个问题的解决办法是问题中描述的替代建议 下面是类的详细信息,以便您可以查看本机实现,了解代码应该是什么样子 从以下密封等级开始: 这继承自抽象类: 此类继承名为的方法:
ParseFile
遵循继承的类,直到达到:
您将在此处找到包含读取原始文件和解析内容的起点的方法:
internal void ParseFile(string physicalPath, VirtualPath virtualPath)
{
string o = (physicalPath != null) ? physicalPath : virtualPath.VirtualPathString;
if (this._circularReferenceChecker.Contains(o))
{
this.ProcessError(SR.GetString("Circular_include"));
}
else
{
this._circularReferenceChecker.Add(o);
try
{
StreamReader reader;
if (physicalPath != null)
{
using (reader = Util.ReaderFromFile(physicalPath, base.CurrentVirtualPath))
{
this.ParseReader(reader, virtualPath);
return;
}
}
using (Stream stream = virtualPath.OpenFile())
{
reader = Util.ReaderFromStream(stream, base.CurrentVirtualPath);
this.ParseReader(reader, virtualPath);
}
}
finally
{
this._circularReferenceChecker.Remove(o);
}
}
}
为什么不使用?因为属性名不是Eval的强类型。如果使用我的示例中的方法,属性名称不正确,则会出现编译时错误。使用Eval,您将在运行时发现是否犯了错误。此外,对于我的问题,Eval或Bind的使用并不重要。
string rawPageMarkUp = File.ReadAllText(physicalPathOfAspxPage);
string rawItemTemplate = RegExMethodToExtractItemTemplateFromControl(controlName, rawPageMarkUp);
ParseFile
internal void ParseFile(string physicalPath, VirtualPath virtualPath)
{
string o = (physicalPath != null) ? physicalPath : virtualPath.VirtualPathString;
if (this._circularReferenceChecker.Contains(o))
{
this.ProcessError(SR.GetString("Circular_include"));
}
else
{
this._circularReferenceChecker.Add(o);
try
{
StreamReader reader;
if (physicalPath != null)
{
using (reader = Util.ReaderFromFile(physicalPath, base.CurrentVirtualPath))
{
this.ParseReader(reader, virtualPath);
return;
}
}
using (Stream stream = virtualPath.OpenFile())
{
reader = Util.ReaderFromStream(stream, base.CurrentVirtualPath);
this.ParseReader(reader, virtualPath);
}
}
finally
{
this._circularReferenceChecker.Remove(o);
}
}
}