TemplateControl.ParseControl 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将输入字符串分析为 Control ASP.NET 网页或用户控件上的对象。
重载
| 名称 | 说明 |
|---|---|
| ParseControl(String) |
将输入字符串分析为 Control Web 窗体页面上的对象或用户控件。 |
| ParseControl(String, Boolean) |
将输入字符串分析为 Control ASP.NET 网页或用户控件上的对象。 |
注解
.NET Framework 版本 3.5 中引入了 ParseControl。 有关详细信息,请参阅 版本和依赖项。
ParseControl(String)
将输入字符串分析为 Control Web 窗体页面上的对象或用户控件。
public:
System::Web::UI::Control ^ ParseControl(System::String ^ content);
public System.Web.UI.Control ParseControl(string content);
member this.ParseControl : string -> System.Web.UI.Control
Public Function ParseControl (content As String) As Control
参数
- content
- String
一个包含用户控件的字符串。
返回
已分析 Control的 。
示例
下面的代码示例演示如何使用该方法创建 Button Web 服务器控件,然后将结果添加到ParseControl名为ControlCollection的 PlaceHolder Web 服务器控件的集合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>
<%@ Page language="vb" 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.ParseControl;
' 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.
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
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:placeholder id ="myPlaceholder" runat="server" />
</form>
</body>
</html>
注解
该 content 参数包含用户控件,例如在 .ascx 文件中查找。 此字符串不能包含任何代码,因为 ParseControl 该方法永远不会导致编译。
另请参阅
适用于
ParseControl(String, Boolean)
将输入字符串分析为 Control ASP.NET 网页或用户控件上的对象。
public:
System::Web::UI::Control ^ ParseControl(System::String ^ content, bool ignoreParserFilter);
public System.Web.UI.Control ParseControl(string content, bool ignoreParserFilter);
member this.ParseControl : string * bool -> System.Web.UI.Control
Public Function ParseControl (content As String, ignoreParserFilter As Boolean) As Control
参数
- content
- String
一个包含用户控件的字符串。
- ignoreParserFilter
- Boolean
一个值,指定是否忽略分析器筛选器。
返回
分析的控件。
注解
该 content 参数包含用户控件(.ascx 文件的内容)。 此字符串不能包含任何代码,因为 ParseControl 该方法永远不会导致编译。
该 ignoreParserFilter 参数允许 PageParserFilter 忽略类。 ASP.NET 分析器使用 PageParserFilter 类来确定在分析时是否允许在页面中使用项。