Tuesday, July 17, 2012

TemplateControl.ParseControl the easy way to add controls

The TemplateControl.ParseControl() is a powerfull tool to convert a string into a control, if you want to add controls to your web page this object will help you avoid a lot of coding.





// Create the label control
Control ct = ParseControl("");

// Add the control to the page
Page.Controls.Add(ct);

//
// Create a string with a table and a label
string tbl = "b
Text
"; // Create the control Control ctrl = Page.ParseControl(tbl); // Add it to the page PageControls.Add(ctrl);

No comments:

Post a Comment