次の方法で共有


Page.IsClientScriptBlockRegistered メソッド

メモ : このメソッドは,互換性のために残されています。

指定したキーを持つクライアント スクリプト ブロックがページに登録されているかどうかを判断します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
<ObsoleteAttribute("The recommended alternative is ClientScript.IsClientScriptBlockRegistered(string key). https://go.microsoft.com/fwlink/?linkid=14202")> _
Public Function IsClientScriptBlockRegistered ( _
    key As String _
) As Boolean
'使用
Dim instance As Page
Dim key As String
Dim returnValue As Boolean

returnValue = instance.IsClientScriptBlockRegistered(key)
[ObsoleteAttribute("The recommended alternative is ClientScript.IsClientScriptBlockRegistered(string key). https://go.microsoft.com/fwlink/?linkid=14202")] 
public bool IsClientScriptBlockRegistered (
    string key
)
[ObsoleteAttribute(L"The recommended alternative is ClientScript.IsClientScriptBlockRegistered(string key). https://go.microsoft.com/fwlink/?linkid=14202")] 
public:
bool IsClientScriptBlockRegistered (
    String^ key
)
/** @attribute ObsoleteAttribute("The recommended alternative is ClientScript.IsClientScriptBlockRegistered(string key). https://go.microsoft.com/fwlink/?linkid=14202") */ 
public boolean IsClientScriptBlockRegistered (
    String key
)
ObsoleteAttribute("The recommended alternative is ClientScript.IsClientScriptBlockRegistered(string key). https://go.microsoft.com/fwlink/?linkid=14202") 
public function IsClientScriptBlockRegistered (
    key : String
) : boolean
適用できません。

パラメータ

  • key
    検索対象のクライアント スクリプトの文字列キー。

戻り値

スクリプト ブロックが登録されている場合は true。それ以外の場合は false

解説

Page.RegisterClientScriptBlock を呼び出す前にこのメソッドを呼び出して、クライアント側のスクリプトを不必要にアセンブルしないようにします。この処理は、特に、スクリプトを作成するために大量のサーバー リソースが必要である場合に行ってください。

IsClientScriptBlockRegistered メソッドは推奨されていません。ClientScriptManager クラスの IsClientScriptBlockRegistered メソッドを使用してください。

使用例

IsClientScriptBlockRegistered メソッドと共に RegisterClientScriptBlock メソッドを使用する方法を次のコード例に示します。コード宣言ブロックに書き込まれた ECMAScript がまだ登録されていないことが IsClientScriptBlockRegistered によるチェックで判明した場合は、RegisterClientScriptBlock の呼び出しが実行されます。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ASP.NET Example</title>
<script language="VB" runat="server">
       
       Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
         
         If (Not IsClientScriptBlockRegistered("clientScript")) Then
           
           'Form the script that is to be registered at client side.
            Dim scriptString As String = "<script language=""JavaScript""> function DoClick() {"
           scriptString += "myForm.show.value='Welcome to Microsoft .NET'}<"
           scriptString += "/"
           scriptString += "script>"
           RegisterClientScriptBlock("clientScript", scriptString)
         End If
         
       End Sub
     </script>
  </head>
  <body style="margin-top:20; margin-left:10">
     <form id="myForm" runat="server">
        <input type="text" id="show" style="width:200" />
      <input type="button" value="ClickMe" onclick="DoClick()" />
     </form>
  </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ASP.NET Example</title>
<script language="C#" runat="server">

      public void Page_Load(Object sender, EventArgs e)
      {

        if (!this.IsClientScriptBlockRegistered("clientScript"))
        {
          // Form the script that is to be registered at client side.
          String scriptString = "<script language=\"JavaScript\"> function DoClick() {";
          scriptString += "myForm.show.value='Welcome to Microsoft .NET'}<";
          scriptString += "/";
          scriptString += "script>";
          this.RegisterClientScriptBlock("clientScript", scriptString);
        }
      }

     </script>
  </head>
  <body style="margin-top:20; margin-left:10">
     <form id="myForm" runat="server">
        <input type="text" id="show" style="width:200" /> <input type="button" value="ClickMe" onclick="DoClick()" />
     </form>
  </body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>ASP.NET Example</title>
<script language="VJ#" runat="server">

          public void Page_Load(Object sender, EventArgs e)
          {
            if (!(this.IsClientScriptBlockRegistered("clientScript"))) 
            {
              // Form the script that is to be registered at client side.
              String scriptString = 
                "<script language=\"JavaScript\"> function DoClick() {";
              scriptString += "myForm.show.value='Welcome to Microsoft .NET'}<";
              scriptString += "/";
              scriptString += "script>";
              this.RegisterClientScriptBlock("clientScript", scriptString);
            }
        }//Page_Load
        </script>
    </head>
  <body style="margin-top:20; margin-left:10">
     <form id="myForm" runat="server">
        <input type="text" id="show" style="width:200" /> <input type="button" value="ClickMe" onclick="DoClick()" />
     </form>
  </body>
</html>

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 1.0,1.1,2.0
3.0 では,互換性のために残されています (コンパイル時に警告)

参照

関連項目

Page クラス
Page メンバ
System.Web.UI 名前空間
RegisterClientScriptBlock