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

속성 값

웹 페이지에서 참조되는 클라이언트 스크립트가 들어 있는 ScriptReference 개체입니다.

예제

다음 코드 예제에서는 CustomScript.js 이라고 하는 스크립트 파일을 참조 하는 ASP.NET 웹 페이지를 보여 줍니다. 웹 애플리케이션이 도메인에서 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 이벤트가 발생 합니다.

적용 대상