ClientScriptManager.RegisterForEventValidation Method (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Registers an event reference for validation with a unique control ID representing the client control generating the event.

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

public void RegisterForEventValidation(
	string uniqueId


Type: System.String

A unique ID representing the client control generating the event.

For more information and examples, see the RegisterForEventValidation method.

The following example shows how to use the RegisterForEventValidation method and the ValidateEvent method in order to register a callback for validation, and how to validate that the callback originated from the page.

<%@ Page Language="C#" %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

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

<script runat="server" >

    string _cbMessage = "";
    // Define method that processes the callbacks on server.
    public void RaiseCallbackEvent(String eventArgument)
            _cbMessage = "Correct event raised callback.";
        catch (Exception ex)
            _cbMessage = "Incorrect event raised callback.";

    // Define method that returns callback result.
    public string GetCallbackResult()
        return _cbMessage;

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            ClientScriptManager cs = Page.ClientScript;
            String cbReference = cs.GetCallbackEventReference("'" +
                Page.UniqueID + "'", "arg", "ReceiveServerData", "",
                "ProcessCallBackError", false);
            String callbackScript = "function CallTheServer(arg, context) {" +
                cbReference + "; }";
            cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer",
                callbackScript, true);
    protected override void Render(HtmlTextWriter writer)


<script type="text/javascript">
    var value1 = new Date();
    function ReceiveServerData(arg, context) {
        Message.innerText = arg;
        Label1.innerText = "Callback completed at " + value1;
        value1 = new Date();
    function ProcessCallBackError(arg, context) {
        Message.innerText = 'An error has occurred.';

<html xmlns="" >
<head id="Head1" runat="server">
    <title>CallBack Event Validation Example</title>
    <form id="Form1" runat="server">
      Callback result: <span id="Message"></span>
      <br /> <br />
      <input type="button"
             onclick="CallTheServer(value1, null )"/>
      <br /> <br />
      <asp:Label id="Label1" runat="server"/>

.NET Framework
Available since 2.0
Return to top