クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
System.Web.UI 名前空間
ClientScriptManager クラス
すべて縮小/すべて展開 すべて縮小
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
ClientScriptManager クラス

更新 : 2007 年 11 月

Web アプリケーションのクライアント スクリプトを管理するためのメソッドを定義します。

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

Visual Basic (宣言)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class ClientScriptManager
Visual Basic (使用法)
Dim instance As ClientScriptManager
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class ClientScriptManager
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class ClientScriptManager sealed
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public final class ClientScriptManager
JScript
public final class ClientScriptManager

ClientScriptManager クラスは、クライアント スクリプトを管理し、これらを Web アプリケーションに追加するために使用されます。Page オブジェクトの ClientScript プロパティから、ClientScriptManager クラスへの参照を取得できます。

クライアント スクリプトを Web ページの HTML マークアップに含めると、宣言によってこのスクリプトを Web ページに追加できます。ただし、クライアント スクリプトを動的に追加することが必要な場合もあります。スクリプトを動的に追加するには、RegisterClientScriptBlockRegisterClientScriptIncludeRegisterStartupScript、または RegisterOnSubmitStatement の各メソッドを、スクリプトを追加するタイミングと方法に応じて使用します。詳細については、「方法 : ASP.NET Web ページにクライアント スクリプトを動的に追加する」を参照してください。

ClientScriptManager クラスは、キーの StringType によって一意にスクリプトを識別します。同じキーと型を持つスクリプトは重複していると見なされます。スクリプトの型を使用することにより、同じページ上で使用される可能性のある異なるユーザー コントロールから実行される似たようなスクリプトが混同されることを防ぐことができます。

ポストバックを使用しないでクライアントからサーバー コードを実行する必要がある場合、ClientScriptManager クラスを使用して、クライアント コールバックを起動できます。これは、サーバーに対して帯域外コールバックを実行するとも言います。クライアント コールバックでは、クライアント スクリプト関数は ASP.NET Web ページに非同期要求を送信します。Web ページは、その通常の有効期間の変形バージョンで、コールバックを処理します。GetCallbackEventReference メソッドを使用して、クライアント関数への参照を取得します。この関数が呼び出されると、サーバー イベントに対するクライアント コールバックが開始されます。詳細については、「ASP.NET Web ページでポストバックせずにプログラムによってクライアント コールバックを実装する」を参照してください。

メモ :

スクリプト コールバックは、ドキュメント オブジェクト モデル (DOM: Document Object Model) をサポートしない古いブラウザでは動作しません。また、クライアントで ECMAScript が有効になっていることも必要です。ブラウザがコールバックをサポートしているかどうかをチェックするには、SupportsCallback プロパティを使用します。このプロパティには、ASP.NET 組み込み Request オブジェクトの Browser プロパティからアクセスできます。

クライアント ポストバック イベントを定義するには、GetPostBackEventReference メソッドと GetPostBackClientHyperlink メソッドを使用します。これらのメソッドが呼び出されると、クライアント スクリプト関数が、サーバーからページにポストバックを実行できる状態になります。クライアント ポストバック イベントは、Web ページが通常の有効期間を完了してクライアント ポストバック イベントを処理する点において、クライアント コールバックとは異なります。

メモ :

Button コントロールを使用し、UseSubmitBehavior プロパティが false である場合に、GetPostBackEventReference メソッドを使用して、Button コントロールに対してクライアント ポストバック イベントを返すことができます。

ButtonImageButton、および LinkButton の各コントロールの OnClientClick プロパティを使用して、クライアント スクリプトを実行できます。

TopicLocation
ASP.NET Web ページでポストバックせずにクライアント コールバックを実装するASP .NET Web アプリケーションの作成
ASP.NET Web ページでポストバックせずにプログラムによってクライアント コールバックを実装するVisual Studio ASP .NET での Web アプリケーションの作成
クライアント コールバックの実装例 (C#)ASP .NET Web アプリケーションの作成
クライアント コールバックの実装例 (C#)Visual Studio ASP .NET での Web アプリケーションの作成
クライアント コールバックの実装例 (C#)dv_vwdcon
クライアント コールバックの実装例 (Visual Basic)ASP .NET Web アプリケーションの作成
クライアント コールバックの実装例 (Visual Basic)Visual Studio ASP .NET での Web アプリケーションの作成
クライアント コールバックの実装例 (Visual Basic)dv_vwdcon
ポストバックのないクライアント コールバックを実装します。dv_vwdcon
方法 : ASP.NET Web ページでのコールバック関数を実装します。dv_vwdcon
方法 : ASP.NET Web ページにコールバックを実装するASP .NET Web アプリケーションの作成
方法 : ASP.NET Web ページにコールバックを実装するVisual Studio ASP .NET での Web アプリケーションの作成
検証付きクライアント コールバックの実装例ASP .NET Web アプリケーションの作成
検証付きクライアント コールバックの実装例Visual Studio ASP .NET での Web アプリケーションの作成
検証付きクライアント コールバックの実装例dv_vwdcon

ClientScriptManager クラスの RegisterClientScriptBlock メソッドの使用方法を示すコード例を次に示します。ページには 2 つのクライアント スクリプトが定義されています。1 つはページが読み込まれる際に警告メッセージを表示する PopupScript、もう 1 つは HTML ボタンの onClick イベントに対するクライアント ハンドラを定義する ButtonClickScript です。

Visual Basic
<%@ 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  >
  <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>
C#
<%@ 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  >
  <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>
System..::.Object
  System.Web.UI..::.ClientScriptManager
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

.NET Framework

サポート対象 : 3.5、3.0、2.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件 | 商標 | プライバシー
Page view tracker