ClientScriptManager.IsClientScriptIncludeRegistered Metoda

Definice

Určuje, zda je součástí klientského skriptu zaregistrován objekt Page .

Přetížení

Name Description
IsClientScriptIncludeRegistered(String)

Určuje, zda je klientský skript registrován s objektem Page pomocí zadaného klíče.

IsClientScriptIncludeRegistered(Type, String)

Určuje, zda je klientský skript registrován s Page objektem pomocí klíče a typu.

IsClientScriptIncludeRegistered(String)

Určuje, zda je klientský skript registrován s objektem Page pomocí zadaného klíče.

public:
 bool IsClientScriptIncludeRegistered(System::String ^ key);
public bool IsClientScriptIncludeRegistered(string key);
member this.IsClientScriptIncludeRegistered : string -> bool
Public Function IsClientScriptIncludeRegistered (key As String) As Boolean

Parametry

key
String

Klíč klientského skriptu zahrnuje hledání.

Návraty

trueje-li klientský skript registrován; v opačném případě . false

Poznámky

Před voláním metody zavolejte tuto metodu RegisterClientScriptInclude , abyste se vyhnuli registraci duplicitních skriptů. To je zvlášť důležité, pokud skript k vytvoření vyžaduje velké množství prostředků serveru.

Součástí klientského skriptu je jedinečný identifikátor jeho klíče a jeho typu. Skripty se stejným klíčem a typem se považují za duplicitní.

Toto přetížení IsStartupScriptRegistered metody volá přetížení, které přebírá jak a keytype parametr s typem nastaveným jako objekt.Page

Viz také

Platí pro

IsClientScriptIncludeRegistered(Type, String)

Určuje, zda je klientský skript registrován s Page objektem pomocí klíče a typu.

public:
 bool IsClientScriptIncludeRegistered(Type ^ type, System::String ^ key);
public bool IsClientScriptIncludeRegistered(Type type, string key);
member this.IsClientScriptIncludeRegistered : Type * string -> bool
Public Function IsClientScriptIncludeRegistered (type As Type, key As String) As Boolean

Parametry

type
Type

Typ klientského skriptu zahrnuje hledání.

key
String

Klíč klientského skriptu zahrnuje hledání.

Návraty

trueje-li klientský skript registrován; v opačném případě . false

Výjimky

Typ zahrnutí klientského skriptu je null.

Příklady

Následující příklad kódu ukazuje použití IsClientScriptIncludeRegistered metody. Mějte na paměti, že pokud by logika pro kontrolu existujícího klientského skriptu byla odebrána, nebyly by ve zdrojovém kódu HTML vykreslené stránky dva duplicitní klientské skripty, protože RegisterClientScriptInclude metoda kontroluje duplicity. Výhodou kontroly je snížení nepotřebných výpočtů.

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    public void Page_Load(Object sender, EventArgs e)
    {
        // Define the name, type and url of the client script on the page.
        String csname = "ButtonClickScript";
        String csurl = "~/script_include.js";
        Type cstype = this.GetType();

        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = Page.ClientScript;

        // Check to see if the include script exists already.
        if (!cs.IsClientScriptIncludeRegistered(cstype, csname))
        {
            cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl(csurl));
        }

    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form id="Form1" runat="server">
     <div>
        <input type="text"
               id="Message"/> 
        <input type="button" 
               value="ClickMe"
               onclick="DoClick()"/>
     </div>
     </form>
  </body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

        ' Define the name, type and url of the client script on the page.
        Dim csname As String = "ButtonClickScript"
        Dim csurl As String = "~/script_include.js"
        Dim cstype As Type = Me.GetType()
    
        ' Get a ClientScriptManager reference from the Page class.
        Dim cs As ClientScriptManager = Page.ClientScript
    
        ' Check to see if the include script is already registered.
        If (Not cs.IsClientScriptIncludeRegistered(cstype, csname)) Then
      
            cs.RegisterClientScriptInclude(cstype, csname, ResolveClientUrl(csurl))
      
        End If
    
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ClientScriptManager Example</title>
</head>
<body>
     <form id="Form1" runat="server">
     <div>
        <input type="text"
               id="Message"/> 
        <input type="button" 
               value="ClickMe"
               onclick="DoClick()"/>
     </div>
     </form>
</body>
</html>

Tento příklad vyžaduje javascriptový soubor s názvem Script_include.jss následujícím obsahem:

function DoClick() {Form1.Message.value='Text from include script.'}

Poznámky

Před voláním metody zavolejte tuto metodu RegisterClientScriptInclude , aby se zabránilo registraci duplicitního klientského skriptu obsahuje. To je zvlášť důležité, pokud skript k vytvoření vyžaduje velké množství prostředků serveru.

Součástí klientského skriptu je jedinečný identifikátor jeho klíče a jeho typu. Skripty se stejným klíčem a typem se považují za duplicitní. Typ zadáte na základě objektu, který bude přistupovat k prostředku. Pokud například pro přístup k prostředku použijete instanci stránky, zadáte Page typ.

Viz také

Platí pro