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 = "Fail";
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());
52 <script type="text/javascript">
53 var value1 = new Date();
54 function ReceiveServerData(arg, context)
56 Message.innerText = arg;
57 Label1.innerText = "Callback completed at " + value1;
60 function ProcessCallBackError(arg, context)
62 Message.innerText = 'An error has occurred.';
67 <head id="Head1" runat="server">
68 <title>CallBack Event Validation Example</title>
71 <form id="Form1" runat="server">
73 Callback result: <span id="Message"></span>
78 value="ClientCallBack"
79 onclick="CallTheServer(value1, null )"/>
81 <asp:Label id="Label1" runat="server"/>