Revision: 13988
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 14, 2009 15:08 by jasonseney
Initial Code
public static void PlaceHolderToTag(PlaceHolder holder, string tag, HtmlAttr[] attributes) { if (!holder.Visible) { return; } //Init new control to use as tag HtmlControl newControl = new HtmlGenericControl(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(); }
Initial URL
Initial Description
## 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)
Initial Title
Convert ASP.NET PlaceHolder to HTML tag with attributes
Initial Tags
html, c, aspnet
Initial Language
C#