ScriptReferenceEventArgs.Script Vlastnost

Definice

ScriptReference Získá objekt, který obsahuje knihovnu skriptů.

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

Hodnota vlastnosti

Objekt ScriptReference , který obsahuje klientský skript odkazovaný na webové stránce.

Příklady

Následující příklad kódu ukazuje webovou stránku ASP.NET, která odkazuje na soubor skriptu s názvem CustomScript.js. Pokud je webová aplikace hostovaná v www.contoso.com doméně, vlastnost [ScriptReference.Path]Path je nastavena na hodnotu specifickou pro danou doménu. Obslužná rutina události pro ResolveScriptReference událost zkontroluje adresu URL hostitele a v případě potřeby změní hodnotu vlastnosti [ScriptReference.Path].Path Objekt ScriptReference se načte prostřednictvím Script vlastnosti .

<%@ 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>

Poznámky

Objekt ScriptReference ve Script vlastnosti je přidán do Scripts vlastnosti při vyvolání ResolveScriptReference události.

Platí pro