ScriptManager.RegisterDataItem Method (Control, String)


Sends custom data to a control during partial-page rendering.

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

public void RegisterDataItem(
	Control control,
	string dataItem


Type: System.Web.UI.Control

The control that is receiving the data.

Type: System.String

The data that is sent to the control.

Exception Condition

control is null.


The RegisterDataItem method is called during a postback.


dataItem is already registered for control.

Use the RegisterDataItem method to send data from the server to the client during asynchronous postbacks, regardless of whether the control receiving the data is inside an UpdatePanel control.

The RegisterDataItem method can be called only during an asynchronous postback. To determine whether a postback is asynchronous, use the IsInAsyncPostBack property. This method invokes the overload that takes a parameter named isJsonSerialized that is set to false. When the isJsonSerialized parameter is set to false, the string is not serialized as JavaScript Object Notation (JSON). For more information about the JSON format, see the Introducing JSON Web site.

The data items that are registered with the RegisterDataItem method can be accessed in client script during the , , and events of the object. When you handle these events, the custom data is passed in an event argument object. For example, if you provide a handler for the event, the custom data is passed in the class, which exposes a property.

The following example shows how to send data to two Label controls on a page during an asynchronous postback. The Label controls are not inside an UpdatePanel control.


The data that is sent in this example is for illustration only. In a real-world application, you would use the RegisterDataItem method to send custom data from the server.

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

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

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
        if (ScriptManager1.IsInAsyncPostBack)
            System.Web.Script.Serialization.JavaScriptSerializer json =
                new System.Web.Script.Serialization.JavaScriptSerializer();
            ScriptManager1.RegisterDataItem(Label1, DateTime.Now.ToString());
            ScriptManager1.RegisterDataItem(Label2, json.Serialize("more data"), true);

<html xmlns="" >
<head runat="server">
    <title>ScriptManager RegisterDataItem Example</title>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <script type="text/javascript" language="javascript">
        function PageLoadingHandler(sender, args) {
            var dataItems = args.get_dataItems();
            if ($get('Label1') !== null)
                $get('Label1').innerHTML = dataItems['Label1'];
            if ($get('Label2') !== null)
                $get('Label2').innerHTML = dataItems['Label2'];
    <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
       UpdatePanel content.
       <asp:Button ID="Button1" Text="Submit" runat="server" />
    <hr />
    <asp:Label ID="Label1" runat="server" /> <br />
    <asp:Label ID="Label2" runat="server" />

.NET Framework
Available since 3.5
Return to top