1 <%@ Page Language="C#" %>
2 <%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 <html xmlns="http://www.w3.org/1999/xhtml" >
6 <script runat="server" >
8 string _eventName = "Test";
9 string _cbMessage = "";
10 // Define method that processes the callbacks on server.
11 public void RaiseCallbackEvent(String eventArgument)
14 this.ClientScript.ValidateEvent (_eventName, this.ToString ());
15 _cbMessage = "Correct event raised callback.";
17 catch (Exception ex) {
18 _cbMessage = "Incorrect event raised callback.";
22 // Define method that returns callback result.
23 public string GetCallbackResult()
28 protected void Page_Load(object sender, EventArgs e)
32 ClientScriptManager cs = Page.ClientScript;
33 String cbReference = cs.GetCallbackEventReference ("'" +
34 Page.UniqueID + "'", "arg", "ReceiveServerData", "",
35 "ProcessCallBackError", false);
36 String callbackScript = "function CallTheServer(arg, context) {" +
38 cs.RegisterClientScriptBlock (this.GetType (), "CallTheServer",
39 callbackScript, true);
44 protected override void Render(HtmlTextWriter writer)
46 this.ClientScript.RegisterForEventValidation("Test", this.ToString());
50 public override string ToString () {
51 return GetType ().Name;
56 <script type="text/javascript">
57 var value1 = new Date();
58 function ReceiveServerData(arg, context)
60 Message.innerText = arg;
61 Label1.innerText = "Callback completed at " + value1;
64 function ProcessCallBackError(arg, context)
66 Message.innerText = 'An error has occurred.';
71 <head id="Head1" runat="server">
72 <title>CallBack Event Validation Example</title>
75 <form id="Form1" runat="server">
77 Callback result: <span id="Message"></span>
82 value="ClientCallBack"
83 onclick="CallTheServer(value1, null )"/>
85 <asp:Label id="Label1" runat="server"/>