ScriptReference.Assembly Proprietà

Definizione

Ottiene o imposta il nome dell'assembly contenente il file script client come risorsa incorporata.Gets or sets the name of the assembly that contains the client script file as an embedded resource.

public:
 property System::String ^ Assembly { System::String ^ get(); void set(System::String ^ value); };
public string Assembly { get; set; }
member this.Assembly : string with get, set
Public Property Assembly As String

Valore della proprietà

Nome completo o parzialmente qualificato dell'assembly che contiene un file script client come risorsa incorporata.The fully qualified or partially qualified name of the assembly that contains a client script file as an embedded resource.

Esempi

Nell'esempio seguente viene illustrato come fare riferimento a un controllo personalizzato e a un file JavaScript incorporato nell'assembly del controllo.The following example shows how to reference a custom control and a JavaScript file that is embedded in the control assembly. Si presuppone che l'assembly si trovi nella cartella bin del sito Web.The assembly is assumed to be in the Bin folder of the Web site. Il controllo personalizzato anima UpdatePanel i controlli.The custom control animates UpdatePanel controls. Il file JavaScript viene compilato come una risorsa incorporata denominata SampleControl. UpdatePanelAnimation. js.The JavaScript file is compiled as an embedded resource that is named SampleControl.UpdatePanelAnimation.js. Il file JavaScript incorporato viene registrato usando le Assembly proprietà e. NameYou register the embedded JavaScript file by using the Assembly and Name properties.

Per usare questo esempio, compilare il file JavaScript illustrato nell'esempio come risorsa incorporata con il controllo personalizzato.To use this example, compile the JavaScript file that is shown in the example as an embedded resource with the custom control. Inserire l'assembly risultante nella cartella bin del sito Web.Put the resulting assembly into the Bin folder of the Web site. Per un esempio di come incorporare un file JavaScript in un assembly, vedere procedura dettagliata: Incorporamento di un file JavaScript come risorsa in un assembly.For an example of how to embed a JavaScript file in an assembly, see Walkthrough: Embedding a JavaScript File as a Resource in an Assembly.

Nell'esempio seguente viene illustrata una pagina che utilizza il controllo personalizzato.The following example shows a page that uses the custom control.

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

Nell'esempio seguente viene illustrata la definizione della classe del controllo personalizzato.The following example shows the custom control class definition.

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

Nell'esempio seguente viene illustrato il file JavaScript di supporto.The following example shows the supporting JavaScript file.

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);
    }
}
        

Nell'esempio seguente viene illustrato il codice che è necessario aggiungere al file AssemblyInfo del progetto che contiene il controllo personalizzato e il file JavaScript.The following example shows code that you must add to the AssemblyInfo file of the project that contains the custom control and the JavaScript file.

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

Commenti

È possibile impostare Assembly la proprietà quando si fa riferimento a un file di script client incluso come risorsa incorporata in un assembly.You set the Assembly property when you reference a client script file that is included as an embedded resource in an assembly. Impostare Assembly sul nome completo o parzialmente qualificato dell'assembly.Set Assembly to the fully qualified or partially qualified assembly name. Un nome di assembly completo include un nome, una lingua, una chiave pubblica e un numero di versione.A fully qualified assembly name includes a name, culture, public key, and version number. Un nome di assembly parzialmente completo include solo un nome.A partially qualified assembly name includes only a name.

Quando si specifica un valore per Assembly, è necessario specificare anche il nome della risorsa incorporata Name nella proprietà.When you specify a value for Assembly, you must also specify the name of the embedded resource in the Name property. In caso contrario InvalidOperationException , verrà generata un'eccezione.Otherwise, an InvalidOperationException will be thrown.

L'assembly a cui si fa riferimento deve trovarsi nella cartella bin del sito Web o nel Global Assembly Cache.The assembly being referenced must be located in either the Bin folder of the Web site or in the global assembly cache.

Si applica a