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 ページリソース概要



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS