This documentation is archived and is not being maintained.

ScriptManager.RegisterClientScriptInclude Method (Control, Type, String, String)

Registers a client script file with the ScriptManager control for use with a control that is inside an UpdatePanel control, and then adds a script file reference to the page.

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

public static void RegisterClientScriptInclude(
	Control control,
	Type type,
	string key,
	string url


Type: System.Web.UI.Control
The control that is registering the client script file.
Type: System.Type
The type of the client script file. This parameter is usually specified by using the typeof operator (C#) or the GetType operator (Visual Basic) to retrieve the type of the control that is registering the script.
Type: System.String
A unique identifier for the script file.
Type: System.String
The URL of the script file.


The client script file type is null.

- or -

The control that is registering the script file is null.


The control that is registering the script file is not in the page's control tree.

- or -

url is null.

- or -

url is empty.

You use the RegisterClientScriptInclude method to register a client script file for a page or part of a page that is participating in partial-page updates. Client script files that are registered by using this method are sent to the page only when the control represents a control that is inside an UpdatePanel control that is being updated. To register a script file every time that an asynchronous postback occurs, use the RegisterClientScriptInclude(Page, Type, String, String) overload of this method.

If you want to register a script block that does not pertain to partial-page updates, and if you want to register the script block only one time during initial page rendering, use the RegisterClientScriptBlock method of the ClientScriptManager class. You can get a reference to the ClientScriptManager object from the ClientScript property of the page.

The RegisterClientScriptInclude method registers a client script file on the page by rendering a script element whose opening tag contains a src attribute. The url parameter is used to set the src attribute. To resolve URLs, use the ResolveClientUrl method. This method uses the context of the URL it is called for to resolve the path.

Both the RegisterClientScriptInclude and RegisterClientScriptResource methods render script files to the browser. If a script with the same type and key (for a script file) or the same type and resource name (for an embedded resource) is already rendered, the script is not rendered again.

<%@ Page Language="C#" %>

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

<script runat="server">
    public void Page_Load(Object sender, EventArgs e)
        if (!IsPostBack)
            Calendar1.SelectedDate = DateTime.Today;

    protected void Page_PreRender(object sender, EventArgs e)
    protected void IncrementButton_Click(object sender, EventArgs e)
        Calendar1.SelectedDate = Calendar1.SelectedDate.AddDays(1.0);
    protected void DecrementButton_Click(object sender, EventArgs e)
        Calendar1.SelectedDate = Calendar1.SelectedDate.AddDays(-1.0);


<html xmlns="">
<head runat="server">
    <title>ScriptManager RegisterClientScriptInclude</title>
    <style type="text/css">
      background-color: Green;
      top: 95%;
      left: 1%;
      position: absolute;
      visibility: hidden;
    <form id="Form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1"

            <script type="text/javascript">

            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional"
                    <asp:Calendar ID="Calendar1" runat="server"/>
                    <br />
                    Change the selected date: 
                    <asp:Button runat="server" ID="DecrementButton" Text="-" OnClick="DecrementButton_Click" />
                    <asp:Button runat="server" ID="IncrementButton" Text="+" OnClick="IncrementButton_Click" />

            <div id="NotifyDiv" class="MessageStyle">
                Updates are complete.

function Notify(sender, arg)
    ActivateAlertDiv('visible', 'NotifyDiv');
    setTimeout("ActivateAlertDiv('hidden', 'NotifyDiv')", 1000);
function ActivateAlertDiv(visstring, elem)
    var adiv = document.getElementById(elem); = visstring;

.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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