ScriptReferenceEventArgs.Script Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
ScriptReference Mendapatkan objek yang berisi pustaka skrip.
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
Nilai Properti
Objek ScriptReference yang berisi skrip klien yang dirujuk pada halaman Web.
Contoh
Contoh kode berikut menunjukkan halaman web ASP.NET yang mereferensikan file skrip yang diberi nama CustomScript.js. Ketika aplikasi Web dihosting di www.contoso.com
domain, properti [ScriptReference.Path]Path diatur ke nilai khusus untuk domain tersebut. Penanganan aktivitas untuk ResolveScriptReference peristiwa memeriksa URL host dan mengubah nilai untuk properti [ScriptReference.Path]Path jika perlu. Objek ScriptReference diambil melalui Script properti .
<%@ 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>
Keterangan
Objek ScriptReference dalam Script properti ditambahkan ke Scripts properti saat ResolveScriptReference peristiwa dinaikkan.
Berlaku untuk
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk