ScriptReferenceEventArgs.Script 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
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 추가됩니다.