ClientScriptManager.RegisterArrayDeclaration メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ClientScriptManager.RegisterArrayDeclaration メソッドの意味・解説 

ClientScriptManager.RegisterArrayDeclaration メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

配列名と配列値を使用してJavaScript 配列宣言Page オブジェクト登録します

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

Public Sub RegisterArrayDeclaration ( _
    arrayName As String, _
    arrayValue As String _
)
Dim instance As ClientScriptManager
Dim arrayName As String
Dim arrayValue As String

instance.RegisterArrayDeclaration(arrayName, arrayValue)
public void RegisterArrayDeclaration (
    string arrayName,
    string arrayValue
)
public:
void RegisterArrayDeclaration (
    String^ arrayName, 
    String^ arrayValue
)
public void RegisterArrayDeclaration (
    String arrayName, 
    String arrayValue
)
public function RegisterArrayDeclaration (
    arrayName : String, 
    arrayValue : String
)

パラメータ

arrayName

登録する配列名。

arrayValue

登録する配列値。

解説解説

RegisterArrayDeclaration は、arrayName パラメータ指定された名前と同じ名前の配列が既に登録されていないかどうか確認し、同じ名前の登録済み配列存在する場合は、arrayValue パラメータ指定された値を追加します基底ストレージ機構が ArrayList に基づくため、重複許可されます。arrayName パラメータと同じ名前の登録済み配列存在しない場合配列作成されarrayValue パラメータの値がその配列追加されます。

結果JavaScript 配列に文字リテラル含め場合arrayValue パラメータ内に単一引用符 (') またはエスケープされた二重引用符 (\") を含めます。また、JavaScript は、コンマ (,) を配列内の要素区切り記号として処理しますarrayValue パラメータ内の 2 つの項目をコンマ区切った場合RegisterArrayDeclaration メソッドを 2 回呼び出すことと同じ効果なります。この場合1 回呼び出しにより 1 つの項目が処理されます。

使用例使用例

RegisterArrayDeclaration メソッドと RegisterHiddenField メソッド使用方法を示すコード例次に示します。この例では、配列隠し値を登録し配列2 つの値と隠し値の合計計算する <input> ボタンOnClick イベント定義します

<%@ Page Language="VB" %>

<script runat="server">

  Protected Sub Page_Load(ByVal
 sender As Object, ByVal
 e As System.EventArgs)

    ' Define the array name and values.
    Dim arrName As String
 = "MyArray"
    Dim arrValue As String
 = """1"", ""2"",
 ""text"""
    
    ' Define the hidden field name and initial value.
    Dim hiddenName As String
 = "MyHiddenField"
    Dim hiddenValue As String
 = "3"
    
    ' Define script name and type.
    Dim csname As String
 = "ConcatScript"
    Dim cstype As Type = Me.GetType()
        
    ' Get a ClientScriptManager reference from the Page class.
    Dim cs As ClientScriptManager = Page.ClientScript

    ' Register the array with the Page class.
    cs.RegisterArrayDeclaration(arrName, arrValue)
    
    ' Register the hidden field with the Page class.
    cs.RegisterHiddenField(hiddenName, hiddenValue)

    ' Check to see if the  script is already registered.
    If (Not cs.IsClientScriptBlockRegistered(cstype,
 csname)) Then
      Dim cstext As StringBuilder = New
 StringBuilder()
      cstext.Append("<script type=text/javascript> function
 DoClick() {")
      cstext.Append("Form1.Message.value='Sum = ' + ")
      cstext.Append("(parseInt(" + arrName + "[0])+")
      cstext.Append("parseInt(" + arrName + "[1])+")
      cstext.Append("parseInt(" + Form1.Name + "."
 + hiddenName + ".value));} </")
      cstext.Append("script>")
      cs.RegisterClientScriptBlock(cstype, csname, cstext.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" 
            onclick="DoClick()" 
            value="Run Script">
     </form>
  </body>
</html>
<%@ Page Language="C#"%>

<script runat="server">
 
  public void Page_Load(Object sender, EventArgs
 e)
  {
    // Define the array name and values.
    String arrName = "MyArray";
    String arrValue = "\"1\", \"2\", \"text\"";
    
    // Define the hidden field name and initial value.
    String hiddenName = "MyHiddenField";
    String hiddenValue = "3";
    
    // Define script name and type.
    String csname = "ConcatScript";
    Type cstype = this.GetType();
        
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Register the array with the Page class.
    cs.RegisterArrayDeclaration(arrName, arrValue);

    // Register the hidden field with the Page class.
    cs.RegisterHiddenField(hiddenName, hiddenValue);

    // Check to see if the  script is already registered.
    if (!cs.IsClientScriptBlockRegistered(cstype, csname))
    {
      StringBuilder cstext = new StringBuilder();
      cstext.Append("<script type=text/javascript> function DoClick()
 {");
      cstext.Append("Form1.Message.value='Sum = ' + ");
      cstext.Append("(parseInt(" + arrName + "[0])+");
      cstext.Append("parseInt(" + arrName + "[1])+");
      cstext.Append("parseInt(" + Form1.Name + "." + hiddenName
 + ".value));} </");
      cstext.Append("script>");
      cs.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), false);
    }
  }
</script>
<html>
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     <input type="text"
            id="Message" />
     <input type="button" 
            onclick="DoClick()" 
            value="Run Script">
     </form>
  </body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ClientScriptManager クラス
ClientScriptManager メンバ
System.Web.UI 名前空間
Split


このページでは「.NET Framework クラス ライブラリ リファレンス」からClientScriptManager.RegisterArrayDeclaration メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からClientScriptManager.RegisterArrayDeclaration メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からClientScriptManager.RegisterArrayDeclaration メソッドを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ClientScriptManager.RegisterArrayDeclaration メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ClientScriptManager.RegisterArrayDeclaration メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS