Reading raw ItemTemplate Markup of ASP.Net Control
<p>I would like to know if it is possible to read the raw markup of an ItemTemplate from within a repeater control?</p>

<p>Consider the repeater below:</p>

<pre><code>&lt;asp:Repeater ID="uiReport" runat="server" EnableViewState="False"&gt;
    &lt;HeaderTemplate&gt;
        &lt;table border="1"&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th&gt;Product&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
    &lt;/HeaderTemplate&gt;
    &lt;ItemTemplate&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;%#((Product)Container.DataItem).ProductName%&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/ItemTemplate&gt;
    &lt;FooterTemplate&gt;
        &lt;/tbody&gt;&lt;/table&gt;
    &lt;/FooterTemplate&gt;
&lt;/asp:Repeater&gt; 
</code></pre>

<p>I'm attempting to read the item template in its raw string format e.g as a string that would look as below:</p>

<pre><code>string itemTemplate = "&lt;tr&gt;&lt;td&gt;&lt;%#((Product)Container.DataItem).ProductName%&gt;&lt;/td&gt;&lt;/tr&gt;"
</code></pre>

<p>Using Reflector and looking through the call stack has lead me to the following method as per the call stack screen grab below (see first line highlighted):</p>

<p><img src="http://i.stack.imgur.com/9TEhE.png" alt="call stack"></p>

<p>I'm assuming that from within *..._<em>BuildControl</em>_control6()...* the raw contents of the markup in the .aspx page are read, chopped up (RegEx?) and passed as parameters to the below method:</p>

<pre><code>System.Web.UI.DataBoundLiteralControl.SetStaticString(index, s);
</code></pre>

<p>For the Repeater control in this example the 's' (string) parameter has the value:</p>

<pre><code>\r\n                &lt;tr&gt;\r\n                    &lt;td&gt;
</code></pre>

<p>Note the string has been split on the first instance of &lt;%#.</p>

<p>An MSDN search confirms that the SetStaticString method supports the .NET Framework infrastructure and is not intended to be used directly from your code.</p>

<p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.databoundliteralcontrol.setstaticstring.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.web.ui.databoundliteralcontrol.setstaticstring.aspx</a></p>

<p>Is there a virtual method I am missing that will allow me to get hold of the raw template markup or is my only option to read the file contents myself (code example below) and override the necessary <em>Render()</em> methods of the Control base class?</p>

<p>Verbose example of code that would manually read the contents of an .aspx page: </p>

<pre><code>string rawPageMarkUp = File.ReadAllText(physicalPathOfAspxPage);
string rawItemTemplate = RegExMethodToExtractItemTemplateFromControl(controlName, rawPageMarkUp);
</code></pre>
