How can I get the content of an asp:placeholder into a variable that I can apply an xml transform on?
Background
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 <asp:placeholders>
so we build up the page by adding/removing calls to place holders.
The overall aim is to replace the html tables that the place holders generate with e.g. <div>
so that the application can be responsive.
Example
An example use of a place holder is
<asp:PlaceHolder ID="TreeHead" runat="server"></asp:PlaceHolder>
which generates the output
<table id="loginBox" style="padding: 2px; margin: 0px;" cellpadding="2">
<tr>
<td><label for="LM_1">Please enter your username</label></td>
<td><input name="LM$1$" type="text" id="LM_1" /></td>
</tr>
<tr>
<td><label for="LM_2">Please enter your password</label></td>
<td><input name="LM$2$" type="password" id="LM_2"/></td>
</tr>
</table>
I want to convert it to something like this:
<div id="loginBox">
<div class="row">
<div class="element"><label for="LM_1">Please enter your username</label> </div>
<div class="element"><input name="LM$1$" type="text" id="LM_1" /> </div>
</div>
<div class="row">
<div class="element"> <label for="LM_2">Please enter your password</label>
</div>
<div class="element"> <input name="LM$2$" type="password" id="LM_2"/> </div>
</div>
My idea is
- Wrap the
<table>
in<xml></xml>
tags - Transform the table using an xslt
- Extract the resulting
<div id="loginBox"></div>
and output it
I'm thinking that I can achieve this with some inline c# in the .ascx file, like
<% string table = "<xml>" + <asp:PlaceHolder ID="TreeHead" runat="server"></asp:PlaceHolder> + "</xml>"; %>
This fails though as I belive any c# code needs to be in the CodeBehind file so I’m stuck. If I can get the table into a variable, then I can follow this example 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
- asp:placeholder contents to string
- http://www.tomot.de/en-us/article/3/asp.net/create-a-control-in-the-codebehind-and-retrieve-its-rendered-output
Question
How can I get the content of an asp:placeholder into a variable that I can apply an xml transform on?
Thank you for any help.