/ Published in: C#

## Markup ##
_Using square [ ] brackets for compatibility with Snipplr comment form_
[asp:PlaceHolder ID="StuffHolder" runat="server" ]
<p>Some stuff in here</p>
[/asp:PlaceHolder]
## Code Behind ##
HtmlAttr[] attributes = {
new HtmlAttr("id","stuff"),
new HtmlAttr("class","container")
};
PlaceHolderToTag(StuffHolder, "div", attributes);
## Result ##
[div id="stuff" class="container"]
<p>Some stuff in here</p>
[/div]
### Notes:
Useful with the "Visible" property on the placeholder, and facilites
programmically setting IDs on DIVs (can set id based on some item name)
_Using square [ ] brackets for compatibility with Snipplr comment form_
[asp:PlaceHolder ID="StuffHolder" runat="server" ]
<p>Some stuff in here</p>
[/asp:PlaceHolder]
## Code Behind ##
HtmlAttr[] attributes = {
new HtmlAttr("id","stuff"),
new HtmlAttr("class","container")
};
PlaceHolderToTag(StuffHolder, "div", attributes);
## Result ##
[div id="stuff" class="container"]
<p>Some stuff in here</p>
[/div]
### Notes:
Useful with the "Visible" property on the placeholder, and facilites
programmically setting IDs on DIVs (can set id based on some item name)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static void PlaceHolderToTag(PlaceHolder holder, string tag, HtmlAttr[] attributes) { if (!holder.Visible) { return; } //Init new control to use as tag //Add attributes foreach (HtmlAttr attr in attributes) { newControl.Attributes.Add(attr.Key, attr.Value); } //Add all the place holder's controls foreach (Control ctrl in holder.Controls) { newControl.Controls.Add(ctrl); } holder.Parent.Controls.Add(newControl); holder.Controls.Clear(); }
Comments
