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

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

ClientScriptManager.RegisterClientScriptResource メソッド

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

型とリソース名を使用してクライアント スクリプト リソースPage オブジェクト登録します

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

Public Sub RegisterClientScriptResource ( _
    type As Type, _
    resourceName As String _
)
Dim instance As ClientScriptManager
Dim type As Type
Dim resourceName As String

instance.RegisterClientScriptResource(type, resourceName)
public void RegisterClientScriptResource (
    Type type,
    string resourceName
)
public:
void RegisterClientScriptResource (
    Type^ type, 
    String^ resourceName
)
public void RegisterClientScriptResource (
    Type type, 
    String resourceName
)
public function RegisterClientScriptResource
 (
    type : Type, 
    resourceName : String
)

パラメータ

type

登録するクライアント スクリプト リソースの型。

resourceName

登録するクライアント スクリプト リソースの名前。

例外例外
例外種類条件

ArgumentNullException

クライアント側リソースの型が null 参照 (Visual Basic では Nothing) です。

ArgumentNullException

クライアント側リソースの名前が null 参照 (Visual Basic では Nothing) です。

または

クライアント側リソース名の長さゼロです。

解説解説
使用例使用例

RegisterClientScriptResource メソッド使用方法を示すコード例次に示します

<%@ Page Language="VB" %>
<%@ Import Namespace="Samples.AspNet.VB.Controls"
 %>

<script runat="server">

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

    ' Define the resource name and type.
    Dim rsname As String
 = "script_include.js"
    Dim rstype As Type = GetType(ClientScriptResourceLabel)
    
    ' Get a ClientScriptManager reference from the Page class.
    Dim cs As ClientScriptManager = Page.ClientScript
    
    ' Write out the web resource url.
    ResourcePath.InnerHtml = cs.GetWebResourceUrl(rstype, rsname)
    
    ' Register the client resource with the page.
    cs.RegisterClientScriptResource(rstype, rsname)
    
  End Sub
  
</script>

<html>
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     The web resource path is 
     <span  id="ResourcePath"
            runat="server"/>.
     <br />
     <br />
     <input type="text" 
            id="Message">     
     <input type="button" 
            onclick="DoClick()" 
            value="ClientClick">
     </form>
  </body>
</html>
<%@ Page Language="C#"%>
<%@ Import Namespace="Samples.AspNet.CS.Controls" %>

<script runat="server">
 
  public void Page_Load(Object sender, EventArgs
 e)
  {
    // Define the resource name and type.
    String rsname = "script_include.js";
    Type rstype = typeof(ClientScriptResourceLabel);
        
    // Get a ClientScriptManager reference from the Page class.
    ClientScriptManager cs = Page.ClientScript;

    // Write out the web resource url.
    ResourcePath.InnerHtml = cs.GetWebResourceUrl(rstype, rsname);

    // Register the client resource with the page.
    cs.RegisterClientScriptResource(rstype, rsname);

  }
</script>
<html>
  <head>
    <title>ClientScriptManager Example</title>
  </head>
  <body>
     <form    id="Form1"
            runat="server">
     The web resource path is 
     <span  id="ResourcePath"
            runat="server"/>.
     <br />
     <br />
     <input type="text" 
            id="Message">     
     <input type="button" 
            onclick="DoClick()" 
            value="ClientClick">
     </form>
  </body>
</html>

プログラムによって WebResourceAttribute メタデータ属性適用し提供されるリソースについてアセンブリマーク付け方法次のコード例示します

Imports Microsoft.VisualBasic
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Security.Permissions

<Assembly: WebResource("script_include.js", "application/x-javascript")>
 
Namespace Samples.AspNet.VB.Controls

    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)>
 _
    Public Class ClientScriptResourceLabel

        ' Put code here that would
        ' go into the private assembly.

    End Class

End Namespace
using System;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;

[assembly: WebResource("script_include.js", "application/x-javascript")]
namespace Samples.AspNet.CS.Controls
{
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class ClientScriptResourceLabel
    {

        // Put code here that would
        // go into the private assembly.

    }
     
}

この例では、次のような内容Script_include.js という名前の JavaScript ファイルが必要です。

function DoClick() {Form1.Message.value='Text from resource script.'}

ClientScriptResourceLabel クラス含まれる Samples.AspNet.CS.Controls アセンブリ内に Script_include.js ファイルリソースとしてコンパイルます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ClientScriptManager クラス
ClientScriptManager メンバ
System.Web.UI 名前空間
GetWebResourceUrl
RegisterClientScriptInclude
AssemblyResourceLoader
WebResourceAttribute
その他の技術情報
httpHandlers 要素 (ASP.NET 設定スキーマ)



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2024 GRAS Group, Inc.RSS