Apropos MSDN link:
http://msdn.microsoft.com/en-us/library/ms178208.aspx
[.NET Framework 4 - ASP.NET]
Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages
Using the code from the above link in the following code snippet, if you keep a break point on the statement "if (IsPostBack)" in the Page_Load event. The control moves into the "if (IsPostBack)" block after the alert, which mean that it is a Postback.
Then, how come you say "...Without Postbacks"?
I am getting confused here.
Can you help please?
Code Snippet:
Expand|Select|Wrap|Line Numbers
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ASPCS2008ClientCallbacksProgrammatically._Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>
- <script runat="server">
- string aStringValue;
- public void RaiseCallbackEvent(String eventArgument)
- {
- aStringValue = eventArgument;
- }
- public string GetCallbackResult()
- {
- return aStringValue;
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- ClientScriptManager cm = Page.ClientScript;
- String cbReference = cm.GetCallbackEventReference(this, "arg", "ReceiveServerData", "");
- String callbackScript = "function CallServer(arg, context) {" + cbReference + "; }";
- cm.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
- if (IsPostBack)
- {
- }
- if (IsCallback)
- {
- }
- }
- </script>
Expand|Select|Wrap|Line Numbers
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title></title>
- <script type="text/javascript">
- function ReceiveServerData(arg, context) {
- Message.innerText = 'Processed callback.';
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <input type="button" value="Callback"
- onclick="CallServer(1, alert('Callback'))"/>
- <br />
- <span id="Message"></span>
- </div>
- </form>
- </body>
- </html>
Thanks.