ScriptReferenceEventArgs Klasa

Definicja

Udostępnia dane dla zdarzenia ResolveScriptReference.

public ref class ScriptReferenceEventArgs : EventArgs
public class ScriptReferenceEventArgs : EventArgs
type ScriptReferenceEventArgs = class
    inherit EventArgs
Public Class ScriptReferenceEventArgs
Inherits EventArgs
Dziedziczenie
ScriptReferenceEventArgs

Przykłady

W poniższym przykładzie pokazano ASP.NET stronę sieci Web, która odwołuje się do pliku skryptu o nazwie CustomScript.js. Gdy aplikacja internetowa jest hostowana w domenie www.contoso.com , właściwość [ScriptReference.Path]Path jest ustawiona na wartość specyficzną dla tej domeny. Procedura obsługi zdarzeń dla ResolveScriptReference zdarzenia sprawdza adres URL hosta i zmienia wartość właściwości [ScriptReference.Path],Path jeśli jest to konieczne.

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

Uwagi

Po renderowaniu ScriptReferenceEventArgs odwołania do skryptu obiekt zawiera ScriptReference obiekt zdefiniowany w wystąpieniu ScriptManager . Można utworzyć program obsługi zdarzeń dla zdarzenia ResolveScriptReference , aby sprawdzić ScriptReference obiekt i zmodyfikować go zgodnie z potrzebami.

Konstruktory

ScriptReferenceEventArgs(ScriptReference)

Inicjuje nowe wystąpienie klasy ScriptReferenceEventArgs.

Właściwości

Script

ScriptReference Pobiera obiekt zawierający bibliotekę skryptów.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy