ClientScriptManager.IsClientScriptIncludeRegistered Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Determina se o script cliente include está registado no Page objeto.
Sobrecargas
| Name | Description |
|---|---|
| IsClientScriptIncludeRegistered(String) |
Determina se o script cliente include está registado com o Page objeto usando a chave especificada. |
| IsClientScriptIncludeRegistered(Type, String) |
Determina se o script cliente include está registado com o Page objeto usando uma chave e um tipo. |
IsClientScriptIncludeRegistered(String)
Determina se o script cliente include está registado com o Page objeto usando a chave especificada.
public:
bool IsClientScriptIncludeRegistered(System::String ^ key);
public bool IsClientScriptIncludeRegistered(string key);
member this.IsClientScriptIncludeRegistered : string -> bool
Public Function IsClientScriptIncludeRegistered (key As String) As Boolean
Parâmetros
- key
- String
A chave do script cliente inclui pesquisar.
Devoluções
true se o script cliente incluir estiver registado; caso contrário, false.
Observações
Chame este método antes de o RegisterClientScriptInclude chamar para evitar registar scripts duplicados. Isto é particularmente importante se o script requer uma grande quantidade de recursos do servidor para ser criado.
Um script cliente include é identificado de forma única pela sua chave e pelo seu tipo. Scripts com a mesma chave e tipo são considerados duplicados.
Esta sobrecarga do IsStartupScriptRegistered método chama a sobrecarga que toma tanto um key como um type parâmetro com o conjunto de tipos como Page objeto.
Ver também
Aplica-se a
IsClientScriptIncludeRegistered(Type, String)
Determina se o script cliente include está registado com o Page objeto usando uma chave e um tipo.
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
Parâmetros
- type
- Type
O tipo do script cliente inclui para procurar.
- key
- String
A chave do script cliente inclui pesquisar.
Devoluções
true se o script cliente incluir estiver registado; caso contrário, false.
Exceções
O tipo de inclusão do script cliente é null.
Exemplos
O exemplo de código seguinte demonstra a utilização do IsClientScriptIncludeRegistered método. Note que, se a lógica para verificar o script cliente existente fosse removida, não haveria dois scripts duplicados no código-fonte HTML da página renderizada porque o RegisterClientScriptInclude método verifica duplicados. O benefício da verificação é reduzir computação desnecessária.
<%@ 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>
Este exemplo requer um ficheiro JavaScript chamado Script_include.js, com o seguinte conteúdo:
function DoClick() {Form1.Message.value='Text from include script.'}
Observações
Chame este método antes de o RegisterClientScriptInclude chamar para evitar registar inclusão duplicada do script cliente. Isto é particularmente importante se o script requer uma grande quantidade de recursos do servidor para ser criado.
Um script cliente include é identificado de forma única pela sua chave e pelo seu tipo. Scripts com a mesma chave e tipo são considerados duplicados. Especificas o tipo com base no objeto que irá aceder ao recurso. Por exemplo, ao usar uma instância Page para aceder ao recurso, especifica o Page tipo.