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

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

ClientScriptManager.GetWebResourceUrl メソッド

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

サーバー側リソースへの URL 参照を取得します。

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

Public Function GetWebResourceUrl ( _
    type As Type, _
    resourceName As String _
) As String
Dim instance As ClientScriptManager
Dim type As Type
Dim resourceName As String
Dim returnValue As String

returnValue = instance.GetWebResourceUrl(type, resourceName)
public string GetWebResourceUrl (
    Type type,
    string resourceName
)
public:
String^ GetWebResourceUrl (
    Type^ type, 
    String^ resourceName
)
public String GetWebResourceUrl (
    Type type, 
    String resourceName
)
public function GetWebResourceUrl (
    type : Type, 
    resourceName : String
) : String

パラメータ

type

サーバー側リソースの型。

resourceName

サーバー側リソースの名前。

戻り値
リソースへの URL 参照。

例外例外
例外の種類条件

ArgumentNullException

Web リソース型が null 参照 (Visual Basic では Nothing) です。

ArgumentNullException

Web リソース名が null 参照 (Visual Basic では Nothing) です。

または

Web リソース名の長さがゼロです。

解説解説
使用例使用例

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

<%@ 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.'}

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

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ClientScriptManager クラス
ClientScriptManager メンバ
System.Web.UI 名前空間
RegisterClientScriptResource
WebResourceAttribute
AssemblyResourceLoader
その他の技術情報
ASP.NET Web ページのリソースの概要


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

英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

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

   

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



ClientScriptManager.GetWebResourceUrl メソッドのページの著作権

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

©2026 GRAS Group, Inc.RSS