TemplateControl.ParseControl TemplateControl.ParseControl TemplateControl.ParseControl TemplateControl.ParseControl Method

定義

在 ASP.NET 網頁或使用者控制項上,將輸入字串剖析為 Control 物件。Parses an input string into a Control object on the ASP.NET Web page or user control.

多載

ParseControl(String) ParseControl(String) ParseControl(String) ParseControl(String)

在 Web Form 網頁或使用者控制項上,將輸入字串剖析為 Control 物件。Parses an input string into a Control object on the Web Forms page or user control.

ParseControl(String, Boolean) ParseControl(String, Boolean) ParseControl(String, Boolean) ParseControl(String, Boolean)

在 ASP.NET 網頁或使用者控制項上,將輸入字串剖析為 Control 物件。Parses an input string into a Control object on the ASP.NET Web page or user control.

備註

ParseControl .NET Framework 3.5 版中引進。ParseControl is introduced in the .NET Framework version 3.5. 如需詳細資訊,請參閱版本和相依性For more information, see Versions and Dependencies.

ParseControl(String) ParseControl(String) ParseControl(String) ParseControl(String)

在 Web Form 網頁或使用者控制項上,將輸入字串剖析為 Control 物件。Parses an input string into a Control object on the Web Forms page or user 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 String String String

字串,包含使用者控制項。A string that contains a user control.

傳回

剖析的 ControlThe parsed Control.

範例

下列程式碼範例示範如何建立Button使用的 Web 伺服器控制項ParseControl方法,然後將結果ControlCollection的集合PlaceHolderWeb 伺服器控制項,名為myPlaceholderThe following code example demonstrates how to create a Button Web server control using the ParseControl method, and then adds the result to the ControlCollection collection of a PlaceHolder Web server control named 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 檔案中。The content parameter contains a user control, such as you would find in an .ascx file. 這個字串不能包含任何程式碼,因為ParseControl方法永遠不會導致編譯。This string cannot contain any code, because the ParseControl method never causes compilation.

另請參閱

ParseControl(String, Boolean) ParseControl(String, Boolean) ParseControl(String, Boolean) ParseControl(String, Boolean)

在 ASP.NET 網頁或使用者控制項上,將輸入字串剖析為 Control 物件。Parses an input string into a Control object on the ASP.NET Web page or user control.

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 String String String

字串,包含使用者控制項。A string that contains a user control.

ignoreParserFilter
Boolean Boolean Boolean Boolean

指定是否忽略剖析器篩選條件的值。A value that specifies whether to ignore the parser filter.

傳回

已經剖析的控制項。The parsed control.

備註

content參數包含使用者控制項 (.ascx 檔案的內容)。The content parameter contains a user control (the contents of an .ascx file). 這個字串不能包含任何程式碼,因為ParseControl方法永遠不會導致編譯。This string cannot contain any code, because the ParseControl method never causes compilation.

ignoreParserFilter參數可讓PageParserFilter来忽略的類別。The ignoreParserFilter parameter allows the PageParserFilter class to be ignored. PageParserFilter類別可由 ASP.NET 剖析器來判斷項目中是否允許頁面是在剖析階段。The PageParserFilter class is used by the ASP.NET parser to determine whether an item is allowed in the page at parse time.

適用於