Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get the content of an asp:placeholder into a variable that I can apply an xml transform on?
    primarykey
    data
    text
    <p>How can I get the content of an asp:placeholder into a variable that I can apply an xml transform on?<br /> <br /></p> <h3>Background</h3> <p>I am trying to customise the layout of a .NET web application. It's an enterprise product that allows me to add/remove blocks of content in ascx files, and change css properties. I don't have access to any CodeBehind files (i.e the .cs source code) but I can possibly write my own .cs's if I know how to add those to the .ascx file. However, the actual content stems from<code>&lt;asp:placeholders&gt;</code> so we build up the page by adding/removing calls to place holders.</p> <p><strong>The overall aim is to replace the html tables that the place holders generate with e.g. <code>&lt;div&gt;</code> so that the application can be responsive.</strong> </p> <h3>Example</h3> <p>An example use of a place holder is </p> <pre><code>&lt;asp:PlaceHolder ID="TreeHead" runat="server"&gt;&lt;/asp:PlaceHolder&gt; </code></pre> <p>which generates the output</p> <pre><code>&lt;table id="loginBox" style="padding: 2px; margin: 0px;" cellpadding="2"&gt; &lt;tr&gt; &lt;td&gt;&lt;label for="LM_1"&gt;Please enter your username&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input name="LM$1$" type="text" id="LM_1" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;label for="LM_2"&gt;Please enter your password&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input name="LM$2$" type="password" id="LM_2"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>I want to convert it to something like this:</p> <pre><code>&lt;div id="loginBox"&gt; &lt;div class="row"&gt; &lt;div class="element"&gt;&lt;label for="LM_1"&gt;Please enter your username&lt;/label&gt; &lt;/div&gt; &lt;div class="element"&gt;&lt;input name="LM$1$" type="text" id="LM_1" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="element"&gt; &lt;label for="LM_2"&gt;Please enter your password&lt;/label&gt; &lt;/div&gt; &lt;div class="element"&gt; &lt;input name="LM$2$" type="password" id="LM_2"/&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p></p> <h3>My idea is</h3> <ol> <li>Wrap the <code>&lt;table&gt;</code> in<code>&lt;xml&gt;&lt;/xml&gt;</code> tags</li> <li>Transform the table using an xslt </li> <li>Extract the resulting <code>&lt;div id="loginBox"&gt;&lt;/div&gt;</code> and output it</li> </ol> <p>I'm thinking that I can achieve this with some inline c# in the .ascx file, like</p> <pre><code>&lt;% string table = "&lt;xml&gt;" + &lt;asp:PlaceHolder ID="TreeHead" runat="server"&gt;&lt;/asp:PlaceHolder&gt; + "&lt;/xml&gt;"; %&gt; </code></pre> <p>This fails though as I belive any c# code needs to be in the <em>CodeBehind</em> file so I’m stuck. If I can get the table into a variable, then I can follow <a href="https://stackoverflow.com/questions/34093/how-to-apply-an-xslt-stylesheet-in-c-sharp">this example</a> to apply the transformation. I have found a couple of links (see below) that do something similar but I believe those require access to the Codebehind (i.e. *.cs) files </p> <ol> <li><a href="https://stackoverflow.com/questions/14321937/aspplaceholder-contents-to-string">asp:placeholder contents to string</a><br /></li> <li><a href="http://www.tomot.de/en-us/article/3/asp.net/create-a-control-in-the-codebehind-and-retrieve-its-rendered-output" rel="nofollow noreferrer">http://www.tomot.de/en-us/article/3/asp.net/create-a-control-in-the-codebehind-and-retrieve-its-rendered-output</a></li> </ol> <h3>Question</h3> <p>How can I get the content of an asp:placeholder into a variable that I can apply an xml transform on? <br /> <br /> Thank you for any help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload