Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Skip Navigation Links.
ScriptManager Class
ScriptManager Constructor
AllowCustomErrorsRedirect Property
AsyncPostBackError Event
AsyncPostBackErrorMessage Property
AsyncPostBackSourceElementID Property
AsyncPostBackTimeout Property
AuthenticationService Property
EnablePageMethods Property
EnablePartialRendering Property
EnableScriptGlobalization Property
EnableScriptLocalization Property
GetCurrent Method (page)
IsDebuggingEnabled Property
IsInAsyncPostBack Property
LoadPostData Method (postDataKey, postCollection)
LoadScriptsBeforeUI Property
OnAsyncPostBackError Method (e)
OnInit Method (e)
OnPreRender Method (e)
OnResolveScriptReference Method (e)
ProfileService Property
RaisePostDataChangedEvent Method
RegisterArrayDeclaration Method
RegisterArrayDeclaration Method (control, arrayName, arrayValue)
RegisterArrayDeclaration Method (page, arrayName, arrayValue)
RegisterAsyncPostBackControl Method (control)
RegisterClientScriptBlock Method
RegisterClientScriptBlock Method (control, type, key, script, addScriptTags)
RegisterClientScriptBlock Method (page, type, key, script, addScriptTags)
RegisterClientScriptInclude Method
RegisterClientScriptInclude Method (control, type, key, url)
RegisterClientScriptInclude Method (page, type, key, url)
RegisterClientScriptResource Method
RegisterClientScriptResource Method (control, type, resourceName)
RegisterClientScriptResource Method (page, type, resourceName)
RegisterDataItem Method
RegisterDataItem Method (control, dataItem)
RegisterDataItem Method (control, dataItem, isJsonSerialized)
RegisterDispose Method (control, disposeScript)
RegisterExpandoAttribute Method (control, controlId, attributeName, attributeValue, encode)
RegisterExtenderControl Method (extenderControl, targetControl)
RegisterHiddenField Method
RegisterHiddenField Method (control, hiddenFieldName, hiddenFieldInitialValue)
RegisterHiddenField Method (page, hiddenFieldName, hiddenFieldInitialValue)
RegisterOnSubmitStatement Method
RegisterOnSubmitStatement Method (control, type, key, script)
RegisterOnSubmitStatement Method (page, type, key, script)
RegisterPostBackControl Method (control)
RegisterScriptControl Method (scriptControl)
RegisterScriptDescriptors Method
RegisterScriptDescriptors Method (extenderControl)
RegisterScriptDescriptors Method (scriptControl)
RegisterStartupScript Method
RegisterStartupScript Method (control, type, key, script, addScriptTags)
RegisterStartupScript Method (page, type, key, script, addScriptTags)
Render Method (writer)
ResolveScriptReference Event
ScriptMode Property
ScriptPath Property
Scripts Property
Services Property
SetFocus Method
SetFocus Method (clientID)
SetFocus Method (control)
SupportsPartialRendering Property
Visible Property

RegisterClientScriptInclude Method (control, type, key, url)

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

Syntax

CSharp

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

VisualBasic

Public Shared Sub RegisterClientScriptInclude ( _
	control As Control, _
	type As Type, _
	key As String, _
	url As String _
)

ManagedCPlusPlus

public:
static void RegisterClientScriptInclude (
	Control^ control, 
	Type^ type, 
	String^ key, 
	String^ url
)

JSharp

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

Parameters

control (Control)

The control that is registering the client script file.

type (Type)

The type of the client script file. This parameter is usually specified by using the typeof (C# Reference) operator (C#) or the GetType Operator operator (Visual Basic) to retrieve the type of the control that is registering the script.

key (String)

The string that uniquely identifies the script file.

url (String)

The URL that points to the script file.

Remarks

The RegisterClientScriptInclude method is used 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 with this method are sent to the page only when the control parameter is inside an UpdatePanel control that is updated. To register a script file each time an asynchronous postback occurs, use the RegisterClientScriptInclude(Page, Type, String, String) overload of this method. If you are registering a script file that does not pertain to partial-page updates and if you want to register a client script file once during initial page rendering, use the RegisterClientScriptInclude(String, String) 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 with a src attribute. The url parameter is used to set the src attribute of the <script> element. To resolve URLs, use the ResolveClientUrl(String) method. This method uses the context of the URL on which it is called to resolve the path.

Both the RegisterClientScriptInclude and RegisterClientScriptResource methods load script files into 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 loaded, the script is not reloaded.

Examples

CS

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

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

<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)
    {
        ScriptManager.RegisterClientScriptInclude(
            this,
            typeof(Page),
            "AlertScript",
            ResolveClientUrl("~/scripts/script_alertdiv.js"));
    }
    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);
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ScriptManager RegisterClientScriptInclude</title>
    <style type="text/css">
	div.MessageStyle
	{
      background-color: Green;
      top: 95%;
      left: 1%;
      position: absolute;
      visibility: hidden;
    }
	</style>
</head>
<body>
    <form id="Form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1"
                               runat="server"/>

            <script type="text/javascript">
            Sys.WebForms.PageRequestManager.instance.add_endRequest(Notify);
            </script>

            <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional"
                runat="server">
                <ContentTemplate>
                    <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" />
                </ContentTemplate>
            </asp:UpdatePanel>

            <div id="NotifyDiv" class="MessageStyle">
                Updates are complete.
            </div>
        </div>
    </form>
</body>
</html>

scripts

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

Exceptions

ExceptionCondition
ArgumentNullException

The client script file type is null.

- or -

The control that is registering the script file is null.

ArgumentException

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

- or -

url is null.

- or -

url is empty.

Assembly: System.Web.Extensions (Module: System.Web.Extensions)