ClientScriptManager.IsClientScriptIncludeRegistered 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
클라이언트 스크립트 포함이 개체에 등록되어 Page 있는지 여부를 확인합니다.
오버로드
| Name | Description |
|---|---|
| IsClientScriptIncludeRegistered(String) |
지정된 키를 사용하여 클라이언트 스크립트 포함이 개체에 Page 등록되었는지 여부를 확인합니다. |
| IsClientScriptIncludeRegistered(Type, String) |
키 및 형식을 사용하여 클라이언트 스크립트 포함이 개체에 Page 등록되는지 여부를 결정합니다. |
IsClientScriptIncludeRegistered(String)
지정된 키를 사용하여 클라이언트 스크립트 포함이 개체에 Page 등록되었는지 여부를 확인합니다.
public:
bool IsClientScriptIncludeRegistered(System::String ^ key);
public bool IsClientScriptIncludeRegistered(string key);
member this.IsClientScriptIncludeRegistered : string -> bool
Public Function IsClientScriptIncludeRegistered (key As String) As Boolean
매개 변수
- key
- String
검색할 클라이언트 스크립트의 키입니다.
반품
true클라이언트 스크립트 포함이 등록되면 이고, 그렇지 않으면 . false
설명
중복 스크립트를 등록하지 않도록 메서드를 RegisterClientScriptInclude 호출하기 전에 이 메서드를 호출합니다. 스크립트에서 만드는 데 많은 양의 서버 리소스가 필요한 경우 특히 중요합니다.
클라이언트 스크립트 포함은 키와 해당 형식으로 고유하게 식별됩니다. 키와 형식이 같은 스크립트는 중복된 것으로 간주됩니다.
메서드의 IsStartupScriptRegistered 이 오버로드는 형식이 개체로 설정된 매개 변수와 key a type 매개 변수를 모두 사용하는 오버로드를 Page 호출합니다.
추가 정보
적용 대상
IsClientScriptIncludeRegistered(Type, String)
키 및 형식을 사용하여 클라이언트 스크립트 포함이 개체에 Page 등록되는지 여부를 결정합니다.
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
매개 변수
- type
- Type
검색할 클라이언트 스크립트의 형식입니다.
- key
- String
검색할 클라이언트 스크립트의 키입니다.
반품
true클라이언트 스크립트 포함이 등록되면 이고, 그렇지 않으면 . false
예외
클라이언트 스크립트 포함 유형은 .입니다 null.
예제
다음 코드 예제에서는 메서드의 사용을 보여 줍니다 IsClientScriptIncludeRegistered . 기존 클라이언트 스크립트 포함을 확인하는 논리가 제거된 경우 메서드가 중복을 확인하므로 렌더링된 페이지의 HTML 소스 코드에는 두 개의 중복 클라이언트 스크립트가 RegisterClientScriptInclude 없습니다. 검사의 이점은 불필요한 계산을 줄이는 것입니다.
<%@ 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>
이 예제에는 다음 내용이 포함된 JavaScript Script_include.js파일이 필요합니다.
function DoClick() {Form1.Message.value='Text from include script.'}
설명
중복 클라이언트 스크립트 포함 등록을 RegisterClientScriptInclude 방지하려면 메서드를 호출하기 전에 이 메서드를 호출합니다. 스크립트에서 만드는 데 많은 양의 서버 리소스가 필요한 경우 특히 중요합니다.
클라이언트 스크립트 포함은 키와 해당 형식으로 고유하게 식별됩니다. 키와 형식이 같은 스크립트는 중복된 것으로 간주됩니다. 리소스에 액세스할 개체에 따라 형식을 지정합니다. 예를 들어 페이지 인스턴스를 사용하여 리소스에 액세스할 때 형식을 지정합니다 Page .