ScriptReferenceEventArgs 类

定义

ResolveScriptReference 事件提供数据。Provides data for the ResolveScriptReference event.

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

示例

下面的示例演示了引用名为 CustomScript 的脚本文件的 ASP.NET 网页。The following example shows an ASP.NET Web page that references a script file that is named CustomScript.js. 当 Web 应用程序承载于www.contoso.com域上时, [ScriptReference]Path属性设置为特定于该域的值。When the Web application is hosted on the www.contoso.com domain, the [ScriptReference.Path]Path property is set to a value specific for that domain. ResolveScriptReference事件的事件处理程序将检查主机 URL, 并根据需要更改 [ScriptReference]Path属性的值。An event handler for the ResolveScriptReference event checks the host URL and changes the value for the [ScriptReference.Path]Path property if it is necessary.

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

注解

在呈现脚本引用时, ScriptReferenceEventArgs对象将ScriptReference包含在ScriptManager实例中定义的对象。When a script reference is rendered, the ScriptReferenceEventArgs object contains the ScriptReference object that is defined in the ScriptManager instance. 可以为ResolveScriptReference事件创建事件处理程序, 以ScriptReference检查对象并根据需要进行修改。You can create an event handler for the ResolveScriptReference event to check the ScriptReference object and modify it as needed.

构造函数

ScriptReferenceEventArgs(ScriptReference)

初始化 ScriptReferenceEventArgs 类的新实例。Initializes a new instance of the ScriptReferenceEventArgs class.

属性

Script

获取包含脚本库的 ScriptReference 对象。Gets the ScriptReference object that contains the script library.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于