ClientScriptManager.IsClientScriptBlockRegistered 메서드

정의

클라이언트 스크립트 블록이 Page 개체에 등록되는지 여부를 결정합니다.

오버로드

IsClientScriptBlockRegistered(String)

클라이언트 스크립트 블록이 지정한 키를 사용하여 Page 개체에 등록되는지 여부를 결정합니다.

IsClientScriptBlockRegistered(Type, String)

클라이언트 스크립트 블록이 키와 형식을 사용하여 Page 개체에 등록되는지 여부를 결정합니다.

IsClientScriptBlockRegistered(String)

클라이언트 스크립트 블록이 지정한 키를 사용하여 Page 개체에 등록되는지 여부를 결정합니다.

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

매개 변수

key
String

검색할 클라이언트 스크립트 블록의 키입니다.

반환

Boolean

클라이언트 스크립트 블록이 등록되면 true이고, 그렇지 않으면 false입니다.

예제

<%@ 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 and type of the client scripts on the page.
    String csname1 = "PopupScript";
    String csname2 = "ButtonClickScript";
    Type cstype = this.GetType();
        
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the startup script is already registered.
    if (!cs.IsStartupScriptRegistered(cstype, csname1))
    {
      String cstext1 = "alert('Hello World');";
      cs.RegisterStartupScript(cstype, csname1, cstext1);
    }

    // Check to see if the client script is already registered.
    if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
    {
      StringBuilder cstext2 = new StringBuilder();
      cstext2.Append("<script type=\"text/javascript\"> function DoClick() {");
      cstext2.Append("Form1.Message.value='Text from client script.'} </");
      cstext2.Append("script>");
      cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString());
    }
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form id="Form1"
         runat="server">
        <input type="text" id="Message" /> <input type="button" value="ClickMe" onclick="DoClick()" />
     </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 and type of the client scripts on the page.
    Dim csname1 As String = "PopupScript"
    Dim csname2 As String = "ButtonClickScript"
    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 startup script is already registered.
    If (Not cs.IsStartupScriptRegistered(cstype, csname1)) Then
      
      Dim cstext1 As String = "alert('Hello World');"
            cs.RegisterStartupScript(cstype, csname1, cstext1)
      
    End If
    
    ' Check to see if the client script is already registered.
    If (Not cs.IsClientScriptBlockRegistered(cstype, csname2)) Then
      
      Dim cstext2 As New StringBuilder()
            cstext2.Append("<script type=""text/javascript""> function DoClick() {")
      cstext2.Append("Form1.Message.value='Text from client script.'} </")
      cstext2.Append("script>")
            cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString())
      
    End If
    
  End Sub
  
</script>

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

설명

이 메서드를 호출 하기 전에 RegisterClientScriptBlock 중복 스크립트가 등록 되지 않게 하는 방법입니다. 이 스크립트를 사용 하려면 많은 양의 서버 리소스를 만들어야 하는 경우에 특히 중요 합니다.

클라이언트 스크립트는 해당 키 및 해당 형식에 따라 고유 하 게 식별 됩니다. 동일한 키와 형식을 사용 하 여 스크립트에는 중복으로 간주 됩니다.

이 오버 로드를 IsClientScriptBlockRegistered 둘 다 사용 하는 오버 로드를 호출 하는 메서드를 keytype 로 설정 된 형식 사용 하 여 매개 변수는 Page 개체

추가 정보

적용 대상

IsClientScriptBlockRegistered(Type, String)

클라이언트 스크립트 블록이 키와 형식을 사용하여 Page 개체에 등록되는지 여부를 결정합니다.

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

매개 변수

type
Type

검색할 클라이언트 스크립트 블록의 형식입니다.

key
String

검색할 클라이언트 스크립트 블록의 키입니다.

반환

Boolean

클라이언트 스크립트 블록이 등록되면 true이고, 그렇지 않으면 false입니다.

예외

클라이언트 스크립트 형식이 null인 경우

예제

다음 코드 예제에서는 IsClientScriptBlockRegistered 메서드. 기존 클라이언트 스크립트 블록을 확인 하는 논리를 제거 된 경우 있습니다 됩니다 수 없습니다 두 개의 중복 된 클라이언트 스크립트 렌더링된 된 페이지의 HTML 소스 코드에서 때문에 RegisterClientScriptBlock 중복에 대 한 메서드를 확인 합니다. 불필요 한 계산을 위해 검사의 장점은입니다.

<%@ 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 and type of the client scripts on the page.
    String csname1 = "PopupScript";
    String csname2 = "ButtonClickScript";
    Type cstype = this.GetType();
        
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Check to see if the startup script is already registered.
    if (!cs.IsStartupScriptRegistered(cstype, csname1))
    {
      String cstext1 = "alert('Hello World');";
      cs.RegisterStartupScript(cstype, csname1, cstext1, true);
    }

    // Check to see if the client script is already registered.
    if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
    {
      StringBuilder cstext2 = new StringBuilder();
      cstext2.Append("<script type=\"text/javascript\"> function DoClick() {");
      cstext2.Append("Form1.Message.value='Text from client script.'} </");
      cstext2.Append("script>");
      cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false);
    }
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form id="Form1"
         runat="server">
        <input type="text" id="Message" /> <input type="button" value="ClickMe" onclick="DoClick()" />
     </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 and type of the client scripts on the page.
    Dim csname1 As String = "PopupScript"
    Dim csname2 As String = "ButtonClickScript"
    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 startup script is already registered.
    If (Not cs.IsStartupScriptRegistered(cstype, csname1)) Then
      
      Dim cstext1 As String = "alert('Hello World');"
      cs.RegisterStartupScript(cstype, csname1, cstext1, True)
      
    End If
    
    ' Check to see if the client script is already registered.
    If (Not cs.IsClientScriptBlockRegistered(cstype, csname2)) Then
      
      Dim cstext2 As New StringBuilder()
            cstext2.Append("<script type=""text/javascript""> function DoClick() {")
      cstext2.Append("Form1.Message.value='Text from client script.'} </")
      cstext2.Append("script>")
      cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), False)
      
    End If
    
  End Sub
  
</script>

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

설명

이 메서드를 호출 하기 전에 RegisterClientScriptBlock 중복 스크립트가 등록 되지 않게 하는 방법입니다. 이 스크립트를 사용 하려면 많은 양의 서버 리소스를 만들어야 하는 경우에 특히 중요 합니다.

클라이언트 스크립트는 해당 키 및 해당 형식에 따라 고유 하 게 식별 됩니다. 동일한 키와 형식을 사용 하 여 스크립트에는 중복으로 간주 됩니다. 리소스에 액세스 하는 개체를 기반으로 형식을 지정할 수 있습니다. 예를 들어 사용 하는 경우는 Page 지정할 리소스에 액세스 하는 인스턴스는 Page 형식입니다.

추가 정보

적용 대상