TemplateControl.ParseControl Method
.NET Framework 2.0
Parses an input string into a Control object on the Web Forms page or user control.
Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
The following code example demonstrates how to create a Button Web server control using the ParseControl method, and then adds the result to the ControlCollection collection of a PlaceHolder Web server control named myPlaceholder.
<%@ Page language="c#" Debug="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ASP.NET Example</title> <script runat="server"> // System.Web.UI.TemplateControl.ParserControl; // The following example demonstrates the method 'ParseControl' of class TemplateControl. // Since TemplateControl is abstract, this sample has been written using 'Page' class which derives from // 'TemplateControl' class. // A button object is created by passing a string to contstruct a button using ASP syntax, to the // 'ParseControl' method. This button is added as one of the child controls of the page and displayed. void Page_Load(object sender, System.EventArgs e) { Control c = ParseControl("<asp:button text='Click here!' runat='server' />"); myPlaceholder.Controls.Add(c); } </script> </head> <body> <form id="form1" runat="server"> <asp:placeholder id ="myPlaceholder" runat="server" /> </form> </body> </html>
void Page_Load(Object sender, System.EventArgs e)
{
Control c = ParseControl("<asp:button text='Click here!'"
+ " runat='server' />");
myPlaceholder.get_Controls().Add(c);
}//Page_Load
Community Additions
ADD
Show: