Sends custom data that is represented by a string to a control during partial-page rendering.
Syntax
CSharp
public void RegisterDataItem (
Control control,
string dataItem
)
VisualBasic
Public Sub RegisterDataItem ( _
control As Control, _
dataItem As String _
)
ManagedCPlusPlus
public:
void RegisterDataItem (
Control^ control,
String^ dataItem
)
JSharp
public void RegisterDataItem (
Control control,
String dataItem
)
Parameters
- control (Control)
The page control that is receiving the data.
- dataItem (String)
The data that is sent to the control.
Remarks
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 in the pageLoading, pageLoaded, and endRequest events of the PageRequestManager object. When you provide a handler for these events, the custom data is passed in an event argument object where you can access the data items. For example, if you provide a handler for the pageLoading event, the custom data is passed in the PageLoadingEventArgs class, which exposes a dataItems property.
Examples
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 of an UpdatePanel control.
noteThe 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.
Exceptions
Assembly: System.Web.Extensions (Module: System.Web.Extensions)