ScriptReference.Name Property


Gets or sets the name of the embedded resource that contains the client script file.

Namespace:   System.Web.UI
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

Public Property Name As String

Property Value

Type: System.String

The name of the client script file that is embedded as a resource in an assembly.

You set the Name property to reference a client script file that is embedded as a resource in an assembly.

If you define values for both the Path and Name properties in the same script reference, the Path property takes precedence.

The following example shows how to reference a custom control and a JavaScript file that is embedded in the control assembly. The assembly is assumed to be in the Bin folder of the Web site. The custom control animates UpdatePanel controls. The JavaScript file is compiled as an embedded resource that is named SampleControl.UpdatePanelAnimation.js. You register the embedded JavaScript file by using the Assembly and Name properties.

To use this example, compile the JavaScript file that is shown in the example as an embedded resource with the custom control. Put the resulting assembly into the Bin folder of the Web site. 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.

The following example shows a page that uses the custom control.

<%@ Page Language="VB" AutoEventWireup="true" %>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns="">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" 
                <asp:ScriptReference Assembly="SampleControl" Name="SampleControl.UpdatePanelAnimation.js" />

                     runat="server" >
            <asp:UpdatePanel ID="UpdatePanel1" 
                    <asp:Calendar ID="Calendar2" 

The following example shows the custom control class definition.

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
            Return _borderColor
        End Get
        Set(ByVal value As Color)
            _borderColor = value
        End Set
    End Property

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

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

    Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
        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, _

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

The following example shows the supporting JavaScript file.

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

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

            function() {{
                s.borderWidth = 0;

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")> 

.NET Framework
Available since 3.5
Return to top