TemplateControl.ParseControl 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將輸入字串解析成 Control ASP.NET 網頁或使用者控制項上的物件。
多載
| 名稱 | Description |
|---|---|
| ParseControl(String) |
將輸入字串解析成 Control 網頁表單頁面或使用者控制項上的物件。 |
| ParseControl(String, Boolean) |
將輸入字串解析成 Control ASP.NET 網頁或使用者控制項上的物件。 |
備註
ParseControl 於 .NET Framework 3.5 版本中引入。 欲了解更多資訊,請參閱 版本與相依關係。
ParseControl(String)
將輸入字串解析成 Control 網頁表單頁面或使用者控制項上的物件。
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網頁伺服器控制,並將結果ParseControl加入名為 ControlCollection的 Web 伺服器控制集合PlaceHoldermyPlaceholder中。
<%@ 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 類別。
PageParserFilter 類別由 ASP.NET 解析器用來判斷某個項目在解析時是否允許進入頁面。