Share via


ControlParser.ParseControl 方法

定義

從指定的標記建立控制項。

多載

ParseControl(IDesignerHost, String)

使用指定的設計工具主應用程式 (Designer Host),從指定的標記建立控制項。

ParseControl(IDesignerHost, String, String)

使用指定的設計工具主應用程式 (Designer Host) 和指示詞,從指定的標記建立控制項。

ParseControl(IDesignerHost, String)

使用指定的設計工具主應用程式 (Designer Host),從指定的標記建立控制項。

public:
 static System::Web::UI::Control ^ ParseControl(System::ComponentModel::Design::IDesignerHost ^ designerHost, System::String ^ controlText);
public static System.Web.UI.Control ParseControl (System.ComponentModel.Design.IDesignerHost designerHost, string controlText);
static member ParseControl : System.ComponentModel.Design.IDesignerHost * string -> System.Web.UI.Control
Public Shared Function ParseControl (designerHost As IDesignerHost, controlText As String) As Control

參數

designerHost
IDesignerHost

IDesignerHost 執行個體,其為頁面的設計工具主應用程式 (Designer Host)。

controlText
String

控制項的 HTML 標記。

傳回

controlText 表示的 Control;如果剖析器無法建置控制項,則為 null

例外狀況

參數無效。

範例

下列程式碼範例示範如何從 HTML 標籤文字建立控制項。 此程式碼範例是針對 類別提供的較大範例的 ControlParser 一部分。

// Create a Web control from the persisted control String*.
System::Web::UI::Control^ ctrl = ControlParser::ParseControl( host, inputForm->tbox->Text->Trim() );
// Create a Web control from the HTML markup.
System.Web.UI.Control ctrl =
    ControlParser.ParseControl(host, inputForm.TBox.Text.Trim());
' Create a Web control from the persisted control string.
Dim ctrl As System.Web.UI.Control = ControlParser.ParseControl(host, inputForm.TxBox.Text.Trim())

備註

方法 ParseControl 會使用設計工具主機的服務,存取代表 ASP.NET 網頁上註冊指示詞的字串。 設計工具主機服務是透過 ReferenceManager 物件的 屬性 RootDesigner 取得,如果無法使用,則 IWebFormReferenceManager 服務會取得。

如果剖析器無法建置控制項,方法 ParseControl 會擲回例外狀況。

另請參閱

適用於

ParseControl(IDesignerHost, String, String)

使用指定的設計工具主應用程式 (Designer Host) 和指示詞,從指定的標記建立控制項。

public:
 static System::Web::UI::Control ^ ParseControl(System::ComponentModel::Design::IDesignerHost ^ designerHost, System::String ^ controlText, System::String ^ directives);
public static System.Web.UI.Control ParseControl (System.ComponentModel.Design.IDesignerHost designerHost, string controlText, string directives);
static member ParseControl : System.ComponentModel.Design.IDesignerHost * string * string -> System.Web.UI.Control
Public Shared Function ParseControl (designerHost As IDesignerHost, controlText As String, directives As String) As Control

參數

designerHost
IDesignerHost

IDesignerHost 執行個體,其為頁面的設計工具主應用程式 (Designer Host)。

controlText
String

控制項的 HTML 標記文字。

directives
String

控制項程式碼要包含的頁面指示詞。

傳回

controlText 表示的 Control

例外狀況

參數無效。

範例

下列程式碼範例示範如何從 HTML 標籤文字建立控制項。 此程式碼範例是針對 類別提供的較大範例的 ControlParser 一部分。

// Create a Web control from the persisted control String*.
System::Web::UI::Control^ ctrl = ControlParser::ParseControl( host, inputForm->tbox->Text->Trim() );
// Create a Web control from the HTML markup.
System.Web.UI.Control ctrl =
    ControlParser.ParseControl(host, inputForm.TBox.Text.Trim());
' Create a Web control from the persisted control string.
Dim ctrl As System.Web.UI.Control = ControlParser.ParseControl(host, inputForm.TxBox.Text.Trim())

備註

方法 ParseControl 會使用設計工具主機的服務,存取代表 ASP.NET 網頁上註冊指示詞的字串。 設計工具主機服務是透過 ReferenceManager 物件的 屬性 RootDesigner 取得,如果無法使用,則 IWebFormReferenceManager 服務會取得。

如果剖析器無法建置控制項,方法 ParseControl 會擲回例外狀況。

另請參閱

適用於