Share via


ScriptReference 클래스

정의

ASP.NET 웹 페이지에 사용할 ECMAScript(JavaScript) 파일을 등록합니다.

public ref class ScriptReference : System::Web::UI::ScriptReferenceBase
public class ScriptReference : System.Web.UI.ScriptReferenceBase
type ScriptReference = class
    inherit ScriptReferenceBase
Public Class ScriptReference
Inherits ScriptReferenceBase
상속
ScriptReference

예제

다음 예제에서는 사용자 지정 컨트롤 및 컨트롤 어셈블리에 포함 된 JavaScript 파일을 참조 하는 방법을 보여 집니다. 어셈블리는 웹 사이트의 Bin 폴더에 있는 것으로 간주됩니다. 사용자 지정 컨트롤은 컨트롤에 애니메이션 효과를 UpdatePanel 줍니다. JavaScript 파일은 SampleControl.UpdatePanelAnimation.js 명명된 포함된 리소스로 컴파일됩니다. 및 Name 속성을 사용하여 Assembly 포함된 JavaScript 파일을 등록합니다.

이 예제를 사용하려면 사용자 지정 컨트롤을 사용하여 예제에 표시된 JavaScript 파일을 포함된 리소스로 컴파일합니다. 결과 어셈블리를 웹 사이트의 Bin 폴더에 넣습니다. 어셈블리에 JavaScript 파일을 포함하는 방법에 대한 예제는 연습: JavaScript 파일을 어셈블리에 리소스로 포함시키는 방법을 참조하세요.

다음 예제에서는 사용자 지정 컨트롤을 사용 하는 페이지를 보여 주는 합니다.

<%@ Page Language="C#" %>
<%@ Register TagPrefix="Samples" Namespace="SampleControl" Assembly="SampleControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ScriptReference</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
                                 EnablePartialRendering="True"
                                 runat="server">
             <Scripts>
                <asp:ScriptReference Assembly="SampleControl" Name="SampleControl.UpdatePanelAnimation.js" />
             </Scripts>
            </asp:ScriptManager>
            
                       
            <Samples:UpdatePanelAnimationWithClientResource 
                     ID="UpdatePanelAnimator1"
                     BorderColor="Green"
                     Animate="true"
                     UpdatePanelID="UpdatePanel1"
                     runat="server" >
            </Samples:UpdatePanelAnimationWithClientResource>
            <asp:UpdatePanel ID="UpdatePanel1" 
                               UpdateMode="Conditional"
                               runat="server">
                <ContentTemplate>
                    <asp:Calendar ID="Calendar2" 
                                  runat="server">
                    </asp:Calendar>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="true" %>

<%@ Register TagPrefix="Samples" Namespace="SampleControl" Assembly="SampleControl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ScriptReference</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" 
                                 EnablePartialRendering="True"
                                 runat="server">
             <Scripts>
                <asp:ScriptReference Assembly="SampleControl" Name="SampleControl.UpdatePanelAnimation.js" />
             </Scripts>
            </asp:ScriptManager>
            
                       
            <Samples:UpdatePanelAnimationWithClientResource 
                     ID="UpdatePanelAnimator1"
                     BorderColor="Green"
                     Animate="true"
                     UpdatePanelID="UpdatePanel1"
                     runat="server" >
            </Samples:UpdatePanelAnimationWithClientResource>
            <asp:UpdatePanel ID="UpdatePanel1" 
                               UpdateMode="Conditional"
                               runat="server">
                <ContentTemplate>
                    <asp:Calendar ID="Calendar2" 
                                  runat="server">
                    </asp:Calendar>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>

다음 예제에서는 사용자 지정 컨트롤 클래스 정의를 보여줍니다.

using System;
using System.Drawing;
using System.Web.UI;
using System.Web;
using System.Globalization;

namespace SampleControl
{
    public class UpdatePanelAnimationWithClientResource : Control
    {
        private string _updatePanelID;
        private Color _borderColor;
        private Boolean _animate;
        public Color BorderColor
        {
            get
            {
                return _borderColor;
            }
            set
            {
                _borderColor = value;
            }
        }

        public string UpdatePanelID
        {
            get
            {
                return _updatePanelID;
            }
            set
            {
                _updatePanelID = value;
            }
        }

        public Boolean Animate
        {
            get
            {
                return _animate;
            }
            set
            {
                _animate = value;
            }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (Animate)
            {

                UpdatePanel updatePanel = (UpdatePanel)FindControl(UpdatePanelID);

                string script = String.Format(
                   CultureInfo.InvariantCulture,
                   @"
Sys.Application.add_load(function(sender, args) {{
var {0}_borderAnimation = new BorderAnimation('{1}');
var panelElement = document.getElementById('{0}');
     if (args.get_isPartialLoad()) {{
        {0}_borderAnimation.animate(panelElement);
    }}
}})
",
                   updatePanel.ClientID,
                   ColorTranslator.ToHtml(BorderColor));

                ScriptManager.RegisterStartupScript(
                    this,
                    typeof(UpdatePanelAnimationWithClientResource),
                    ClientID,
                    script,
                    true);
            }
        }
    }
}
Imports System.Web.UI
Imports System.Drawing
Imports System.Globalization

Public Class UpdatePanelAnimationWithClientResource
    Inherits Control

    Private _updatePanelID As String
    Private _borderColor As Color
    Private _animate As Boolean

    Public Property BorderColor() As Color
        Get
            Return _borderColor
        End Get
        Set(ByVal value As Color)
            _borderColor = value
        End Set
    End Property

    Public Property UpdatePanelID() As String
        Get
            Return _updatePanelID
        End Get
        Set(ByVal value As String)
            _updatePanelID = value
        End Set
    End Property

    Public Property Animate() As Boolean
        Get
            Return _animate
        End Get
        Set(ByVal value As Boolean)
            _animate = value
        End Set
    End Property

    Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
        MyBase.OnPreRender(e)
        If (Animate) Then

            Dim updatePanel As UpdatePanel = CType(Me.FindControl(UpdatePanelID), UpdatePanel)

            Dim script As String = String.Format( _
                   CultureInfo.InvariantCulture, _
                   "Sys.Application.add_load(function(sender, args) {{var {0}_borderAnimation = new BorderAnimation('{1}');var panelElement = document.getElementById('{0}');if (args.get_isPartialLoad()) {{{0}_borderAnimation.animate(panelElement);}}}});", _
                   updatePanel.ClientID, _
                   ColorTranslator.ToHtml(BorderColor))


            ScriptManager.RegisterStartupScript( _
                Me, _
                GetType(UpdatePanelAnimationWithClientResource), _
                ClientID, _
                script, _
                True)
        End If
    End Sub
End Class

다음 예제에서는 지원 JavaScript 파일을 보여줍니다.

BorderAnimation = function(color) {
    this._color = color;
}

BorderAnimation.prototype = {
    animate: function(panelElement) {
        var s = panelElement.style;
        s.borderWidth = '2px';
        s.borderColor = this._color;
        s.borderStyle = 'solid';

        window.setTimeout(
            function() {{
                s.borderWidth = 0;
            }},
            500);
    }
}

다음 예제에서는 사용자 지정 컨트롤 및 JavaScript 파일을 포함하는 프로젝트의 AssemblyInfo 파일에 추가해야 하는 코드를 보여 줍니다.

[assembly: System.Web.UI.WebResource("SampleControl.UpdatePanelAnimation.js", "application/x-javascript")]
<Assembly: System.Web.UI.WebResource("SampleControl.UpdatePanelAnimation.js", "application/x-javascript")>

설명

개체를 통해 ScriptReference 등록하여 ASP.NET 웹 페이지에 JavaScript 파일을 포함할 수 있습니다. 웹 사이트에서 .js 파일(정적 스크립트 파일)로 있는 스크립트 파일을 등록할 수 있습니다. 어셈블리에 리소스로 포함된 스크립트 파일을 등록할 수도 있습니다. 스크립트 파일을 등록한 후 웹 페이지의 클라이언트 스크립트에서 해당 함수를 사용할 수 있습니다.

정적 스크립트 파일을 등록하려면 개체의 속성을 파일의 ScriptReference 상대 위치로 설정합니다Path.

어셈블리에 리소스로 포함된 스크립트 파일을 등록하려면 해당 파일을 포함하는 어셈블리의 이름으로 속성을 설정합니다 Assembly . 그런 다음, Name 어셈블리에 포함된 .js 파일의 이름으로 속성을 설정합니다. 이 경우 스크립트 파일은 연결되지 않고 포함해야 합니다.

스크립트의 ScriptMode 디버그 또는 릴리스 버전을 사용할지 여부를 나타내도록 속성을 설정합니다.

Auto 값을 독립 실행형 스크립트 파일 또는 어셈블리에 리소스로 포함 된 스크립트 파일을 참조 하는지 여부에 따라 서로 다른 결과 생성 합니다. 독립 실행형 스크립트 파일은 속성으로 Path 정의됩니다. 어셈블리 참조를 통해 액세스 해야 합니다 NameAssembly 속성입니다. 에 대 한 결과 Auto 값은 다음과 같습니다.

  • 속성이 지정된 Auto 독립 실행형 스크립트 파일에 Path 적용되면 값은 같아Release집니다.

  • 스크립트 참조 어셈블리에 적용 될 때 Auto 같습니다 Inherit합니다. 개체만 Name 지정, 스크립트를 참조 하는 것입니다. Name 속성이 Path 둘 다 지정된 Path 경우 속성은 대신 Name사용되지만 Auto 값은 여전히 같습니다Inherit.

생성자

ScriptReference()

ScriptReference 클래스의 새 인스턴스를 초기화합니다.

ScriptReference(String)

지정된 경로를 사용하여 ScriptReference 클래스의 새 인스턴스를 초기화합니다.

ScriptReference(String, String)

지정된 이름 및 어셈블리를 사용하여 ScriptReference 클래스의 새 인스턴스를 초기화합니다.

속성

Assembly

클라이언트 스크립트 파일이 포함 리소스로 들어 있는 어셈블리의 이름을 가져오거나 설정합니다.

IgnoreScriptPath
사용되지 않습니다.

리소스에서 클라이언트 스크립트 파일을 등록할 때 URL에 ScriptPath 속성이 포함되는지 여부를 나타내는 값을 가져오거나 설정합니다.

Name

클라이언트 스크립트 파일이 들어 있는 포함 리소스의 이름을 가져오거나 설정합니다.

NotifyScriptLoaded
사용되지 않습니다.

ScriptResourceHandler 개체가 Sys.Application 클래스의 NotifyScriptLoaded 메서드를 호출하기 위해 ECMAScript(JavaScript) 파일 끝에 코드를 자동으로 추가하는지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 ScriptReferenceBase)
Path

웹 페이지를 기준으로 하는 참조되는 클라이언트 스크립트 파일의 경로를 가져오거나 설정합니다.

(다음에서 상속됨 ScriptReferenceBase)
ResourceUICultures

Path 속성에서 지원하는 UI 문화권의 쉼표로 구분된 목록을 가져오거나 설정합니다.

(다음에서 상속됨 ScriptReferenceBase)
ScriptMode

사용할 클라이언트 스크립트 파일의 버전(릴리스 또는 디버그)을 가져오거나 설정합니다.

(다음에서 상속됨 ScriptReferenceBase)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
GetUrl(ScriptManager, Boolean)

src 요소의 script 특성 값으로 렌더링되는 URL을 검색합니다.

IsAjaxFrameworkScript(ScriptManager)

스크립트 참조가 AJAX 스크립트인지 여부를 결정합니다.

IsAjaxFrameworkScript(ScriptManager)

지정된 스크립트 참조가 ASP.NET AJAX 스크립트인지 여부를 결정합니다.

(다음에서 상속됨 ScriptReferenceBase)
IsFromSystemWebExtensions()
사용되지 않습니다.

복합 스크립트에 ASP.NET AJAX 프레임워크 스크립트에 대한 참조가 포함되어 있는지 여부를 나타냅니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

Name 속성이나 Path 속성의 값 또는 형식 이름을 나타내는 문자열을 반환합니다.

적용 대상