ClientScriptManager.ValidateEvent Method (String, String)


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

Validates a client event that was registered for event validation using the RegisterForEventValidation method.

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

public void ValidateEvent(
	string uniqueId,
	string argument


Type: System.String

A unique ID representing the client control generating the event.

Type: System.String

The event arguments passed with the client event.

Exception Condition

uniqueId is null or an empty string ("").

The following code example demonstrates using the RegisterForEventValidation method and the ValidateEvent method to register a callback for validation and to validate that the callback originated from the page. To improve on the validation shown here, you could modify the validation argument parameter to contain information specific to the user such as an identity or role

<%@ 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)
            Page.ClientScript.ValidateEvent(button1.UniqueID, this.ToString());
            _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)
        Page.ClientScript.RegisterForEventValidation(button1.UniqueID, this.ToString());


<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 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