TemplateControl.ParseControl Method
Parses an input string into a Control on the Web Forms page or user control.
[Visual Basic] Public Function ParseControl( _ ByVal content As String _ ) As Control [C#] public Control ParseControl( string content ); [C++] public: Control* ParseControl( String* content ); [JScript] public function ParseControl( content : String ) : Control;
Parameters
- content
- A String that contains a user control.
Return Value
Returns the parsed Control.
Remarks
The content string parameter contains a user control, as you would find in an .ascx file. This string cannot contain any code, since this method never causes compilation.
Example
[Visual Basic, C#] The following example creates a Button Web server control using the ParseControl method and then adds the result to the ControlCollection of a PlaceHolder Web server control named myPlaceholder.
[Visual Basic] Sub Page_Load(sender As Object, e As System.EventArgs) Dim c As Control c = ParseControl("<asp:button text='Click here!' runat='server' />") myPlaceholder.Controls.Add(c) End Sub 'Page_Load [C#] void Page_Load(object sender, System.EventArgs e) { Control c = ParseControl("<asp:button text='Click here!' runat='server' />"); myPlaceholder.Controls.Add(c); }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
TemplateControl Class | TemplateControl Members | System.Web.UI Namespace