ScriptReferenceEventArgs.Script プロパティ

定義

スクリプト ライブラリを格納している ScriptReference オブジェクトを取得します。

public:
 property System::Web::UI::ScriptReference ^ Script { System::Web::UI::ScriptReference ^ get(); };
public System.Web.UI.ScriptReference Script { get; }
member this.Script : System.Web.UI.ScriptReference
Public ReadOnly Property Script As ScriptReference

プロパティ値

Web ページで参照されているクライアント スクリプトを格納している ScriptReference オブジェクト。

次のコード例は、CustomScript.jsという名前のスクリプト ファイルを参照する ASP.NET Web ページを示しています。 Web アプリケーションがドメインで www.contoso.com ホストされている場合、[ScriptReference.Path]Path プロパティは、そのドメインに固有の値に設定されます。 イベントのイベント ハンドラーは ResolveScriptReference ホスト URL をチェックし、必要に応じて [ScriptReference.Path]Path プロパティの値を変更します。 オブジェクトは ScriptReference 、 プロパティを Script 使用して取得されます。

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void ScriptManager1_ResolveScriptReference(object sender, ScriptReferenceEventArgs e)
    {
        if (e.Script.Path.Contains("CustomScript"))
        {
            if (HttpContext.Current.Request.Url.Host.ToLower() == "www.contoso.com")
            {
                e.Script.Path = "http://www.contoso.com/ScriptRepository/CustomScript.js";
            }
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Script Reference Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager OnResolveScriptReference="ScriptManager1_ResolveScriptReference" ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/scripts/CustomScript.js" />
        </Scripts>
        </asp:ScriptManager>
    </div>
    </form>
</body>
</html>
<%@ 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 ScriptManager1_ResolveScriptReference(ByVal sender As Object, ByVal e As ScriptReferenceEventArgs)
        If (e.Script.Path.Contains("CustomScript")) Then
            If (HttpContext.Current.Request.Url.Host.ToLower() = "www.contoso.com") Then
                e.Script.Path = "http://www.contoso.com/ScriptRepository/CustomScript.js"
            End If
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Script Reference Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:ScriptManager OnResolveScriptReference="ScriptManager1_ResolveScriptReference" ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/scripts/CustomScript.js" />
        </Scripts>
     </asp:ScriptManager>
    </div>
    </form>
</body>
</html>

注釈

ScriptReferenceイベントが発生すると、 Script プロパティの Scripts オブジェクトが プロパティにResolveScriptReference追加されます。

適用対象