<%@ Page Language="C #"AutoEventWireup="true"codebehind="WebForm1.aspx.cs"Inherits="Webapplication2.webform1" %><!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Headrunat= "Server"> <title></title></Head><Body> <formID= "Form1"runat= "Server"> <Scripttype= "Text/javascript"> functionGetResult (arg,context) {<%=Page.ClientScript.GetCallbackEventReference ( This, "Arg", "Page_callback", "Context", "Page_Error", false)%>; } functionPage_callback (ARG, context) {document.getElementById ("result"). InnerHTML=Arg; } functionPage_Error (ARG, context) {alert ("Error"); } </Script> <DivID= "Result"> </Div> <inputID= "Button1"type= "button"value= "button"onclick= "GetResult (null,null)" /> </form></Body></HTML>
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;namespacewebapplication2{ Public Partial classWebForm1:System.Web.UI.Page, ICallbackEventHandler {Private stringresult =""; protected voidPage_Load (Objectsender, EventArgs e) { } Public stringGetCallbackResult () {returnresult; } Public voidRaiseCallbackEvent (stringeventargument) {Result=DateTime.Now.ToString (); } }}
An example of an ASP. NET AJAX Call