ClientScriptManager.IsClientScriptIncludeRegistered Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Určuje, zda je součástí klientského Page skriptu zaregistrován objekt.
Přetížení
IsClientScriptIncludeRegistered(String) |
Určuje, zda je klientský skript zaregistrovaný u objektu Page pomocí zadaného klíče. |
IsClientScriptIncludeRegistered(Type, String) |
Určuje, zda je klientský skript zaregistrovaný u objektu Page pomocí klíče a typu. |
IsClientScriptIncludeRegistered(String)
Určuje, zda je klientský skript zaregistrovaný u objektu 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
true
pokud je klientský skript zaregistrovaný; false
v opačném případě .
Poznámky
Před voláním metody volejte tuto metodu RegisterClientScriptInclude , abyste se vyhnuli registraci duplicitních skriptů. To je zvlášť důležité, pokud skript vyžaduje vytvoření velkého množství serverových prostředků.
Klientský skript obsahuje jedinečný identifikátor 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 parametr key
type
, tak s typem nastaveným jako objektem Page .
Viz také
Platí pro
IsClientScriptIncludeRegistered(Type, String)
Určuje, zda je klientský skript zaregistrovaný u objektu Page 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
true
pokud je klientský skript zaregistrovaný; false
v opačném případě .
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 byla logika pro kontrolu existujícího klientského skriptu odebrána, nebyly 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.js
s následujícím obsahem:
function DoClick() {Form1.Message.value='Text from include script.'}
Poznámky
Před voláním metody volejte tuto metodu RegisterClientScriptInclude , abyste zabránili registraci duplicitních klientských skriptů. To je zvlášť důležité, pokud skript vyžaduje vytvoření velkého množství serverových prostředků.
Klientský skript obsahuje jedinečný identifikátor 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. Například při použití instance stránky pro přístup k prostředku zadáte Page
typ.