Convert ASP.NET PlaceHolder to HTML tag with attributes


/ Published in: C#
Save to your folder(s)

## 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)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.