ScriptReference 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
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
- 상속
예제
다음 예제에서는 사용자 지정 컨트롤 및 컨트롤 어셈블리에 포함 된 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 . 어셈블리 참조는 및 Assembly 속성을 통해 Name 액세스해야 합니다. 값의 Auto 결과는 다음과 같습니다.
어셈블리 Auto 의 스크립트 참조에 적용되는 경우와 동일합니다 Inherit. 지정된 경우에만 Name 스크립트를 참조하는 데 사용됩니다. Name 속성이 Path 둘 다 지정된 Path 경우 속성은 대신 Name사용되지만 Auto 값은 여전히 동일합니다Inherit.
생성자
| Name | Description |
|---|---|
| ScriptReference() |
ScriptReference 클래스의 새 인스턴스를 초기화합니다. |
| ScriptReference(String, String) |
지정된 이름과 어셈블리를 ScriptReference 사용하여 클래스의 새 인스턴스를 초기화합니다. |
| ScriptReference(String) |
지정된 경로를 사용하여 클래스의 ScriptReference 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| Assembly |
클라이언트 스크립트 파일을 포함된 리소스로 포함하는 어셈블리의 이름을 가져오거나 설정합니다. |
| IgnoreScriptPath |
사용되지 않음.
리소스에서 클라이언트 스크립트 파일을 등록할 때 속성이 URL에 포함되는지 여부를 ScriptPath 나타내는 값을 가져오거나 설정합니다. |
| Name |
클라이언트 스크립트 파일을 포함하는 포함된 리소스의 이름을 가져오거나 설정합니다. |
| NotifyScriptLoaded |
사용되지 않음.
개체가 Sys.Application 클래스의 클라이언트 NotifyScriptLoaded 메서드를 호출하기 위해 ECMAScript(JavaScript) 파일의 끝에 코드를 자동으로 추가하는지 여부를 ScriptResourceHandler 나타내는 값을 가져오거나 설정합니다. (다음에서 상속됨 ScriptReferenceBase) |
| Path |
웹 페이지를 기준으로 참조된 클라이언트 스크립트 파일의 경로를 가져오거나 설정합니다. (다음에서 상속됨 ScriptReferenceBase) |
| ResourceUICultures |
속성에서 지원하는 Path UI 문화권의 쉼표로 구분된 목록을 가져오거나 설정합니다. (다음에서 상속됨 ScriptReferenceBase) |
| ScriptMode |
사용할 클라이언트 스크립트 파일(릴리스 또는 디버그)의 버전을 가져오거나 설정합니다. (다음에서 상속됨 ScriptReferenceBase) |
메서드
| Name | Description |
|---|---|
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| GetUrl(ScriptManager, Boolean) |
요소의 특성 값 |
| IsAjaxFrameworkScript(ScriptManager) |
스크립트 참조가 AJAX 스크립트인지 여부를 확인합니다. |
| IsFromSystemWebExtensions() |
사용되지 않음.
복합 스크립트에 ASP.NET AJAX 프레임워크 스크립트에 대한 참조가 포함되어 있는지 여부를 나타냅니다. |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |