Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework
 Path Property
.NET Framework Class Library
ScriptReference..::.Path Property

Gets or sets the path of the referenced client script file, relative to the Web page.

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

Visual Basic (Declaration)
Public Property Path As String
Visual Basic (Usage)
Dim instance As ScriptReference
Dim value As String

value = instance.Path

instance.Path = value
C#
public string Path { get; set; }
Visual C++
public:
property String^ Path {
    String^ get ();
    void set (String^ value);
}
JScript
public function get Path () : String
public function set Path (value : String)

Property Value

Type: System..::.String

The path of the referenced client script file.

You set the Path property to register a static client script file (a .js file) that is not embedded as a resource in an assembly. The Path property must include the file name and the script's location relative to the current Web page. When you set the Path property, the ScriptManager object will not use the ScriptPath property to build the URL for the script file.

Always set the Path property to the name of the release version of the client script. If ScriptMode is set to Debug, the ScriptManager control automatically searches for the debug version by changing the file name from file.js to file.debug.js.

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 on a Web site. The custom control animates UpdatePanel controls. You register the JavaScript file by setting the Path property to the location of the file.

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

Visual Basic
<%@ Page Language="VB" AutoEventWireup="true" %>
<%@ Register TagPrefix="Samples" Namespace="SampleControlsVB" %>

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

<html >
<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 Path="scripts/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>

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

<!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 >
<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 Path="scripts/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>

The following example shows the custom control class. Put this code in the App_Code folder if the Web site.

Visual Basic
Imports System.Web.UI
Imports System.Drawing
Imports System.Globalization

Namespace SampleControlsVB

    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
End Namespace

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

namespace SampleControlsCS
{
    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);
            }
        }
    }
}

The following example shows the JavaScript file. This file must be located in a folder that is named Scripts.

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

if(typeof(Sys) !== "undefined")Sys.Application.notifyScriptLoaded();

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

if(typeof(Sys) !== "undefined")Sys.Application.notifyScriptLoaded();

Windows Vista, Windows XP SP2, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker