TemplateControl.ParseControl Metoda

Definice

Analyzuje vstupní řetězec do objektu Control na webové stránce ASP.NET nebo uživatelském ovládacím prvku.

Přetížení

ParseControl(String)

Analyzuje vstupní řetězec do objektu Control na stránce Web Forms nebo uživatelském ovládacím prvku.

ParseControl(String, Boolean)

Analyzuje vstupní řetězec do objektu Control na webové stránce ASP.NET nebo uživatelském ovládacím prvku.

Poznámky

ParseControlje zaveden v .NET Framework verze 3.5. Další informace najdete v tématu Verze a závislosti.

ParseControl(String)

Analyzuje vstupní řetězec do objektu Control na stránce Web Forms nebo uživatelském ovládacím prvku.

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

Parametry

content
String

Řetězec, který obsahuje uživatelský ovládací prvek.

Návraty

Control

Parsovaná Control.

Příklady

Následující příklad kódu ukazuje, jak vytvořit Button ovládací prvek webového serveru pomocí ParseControl metody a pak přidá výsledek do ControlCollection kolekce ovládacího prvku webového PlaceHolder serveru s názvem 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>

Poznámky

Parametr content obsahuje uživatelský ovládací prvek, například byste ho našli v souboru .ascx. Tento řetězec nemůže obsahovat žádný kód, protože ParseControl metoda nikdy nezpůsobí kompilaci.

Viz také

Platí pro

ParseControl(String, Boolean)

Analyzuje vstupní řetězec do objektu Control na webové stránce ASP.NET nebo uživatelském ovládacím prvku.

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

Parametry

content
String

Řetězec, který obsahuje uživatelský ovládací prvek.

ignoreParserFilter
Boolean

Hodnota, která určuje, jestli se má filtr analyzátoru ignorovat.

Návraty

Control

Analyzovaný ovládací prvek.

Poznámky

Parametr content obsahuje uživatelský ovládací prvek (obsah souboru .ascx). Tento řetězec nemůže obsahovat žádný kód, protože ParseControl metoda nikdy nezpůsobí kompilaci.

Parametr ignoreParserFilter umožňuje PageParserFilter ignorovat třídu. Třída PageParserFilter je používána analyzátorem ASP.NET k určení, zda je položka povolena na stránce v době analýzy.

Platí pro