So in essence, here's the gen.
1. Any Asp.Net Page or Control can expose itself to AJAX-style client-side calls and easily perform some server logic before returning some value or other.
2. You just have to implement the System.Web.UI.ICallbackEventHandler interface. This requires two methods, RaiseCallbackEvent(string eventArgument), which receives a request from client-side, and GetCallbackResult() which returns a string to the client.
3. You need to call a special client-script registration method in your ASP.NET code. This example explains it better than I can be bothered to:
string strClientCallbackAutoGubbins = Page.ClientScript.GetCallbackEventReference(this, "RequestArg", "ServerCallResponse", "OptionalContext", true);
string strClientCallbackFunctionCode = "function ServerCall(RequestArg, OptionalContext)" + "{ " + strClientCallbackAutoGubbins + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ServerCall", strClientCallbackFunctionCode, true);
4. Then you just need to implement client script to call the ServerCall client function and get the response back in the ServerCallResponse client function.
5. The format and purpose of the string argument passed to ServerCall, and the format of the response string returned to ServerCallResponse is up to you. You could use JSON, XML or any other bloated WEB2.0ism of your choice - or you could do wot i dun and just pass a bog standard querystring along.
No comments:
Post a Comment
Comments are very welcome but are moderated to prevent spam.