Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qwedster
    New Member
    • Jul 2008
    • 24

    Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages

    Hi Experts!

    Apropos MSDN link:


    [.NET Framework 4 - ASP.NET]
    Implementing Client Callbacks Programmaticall y 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:
    Code:
    <%@ 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>
    Code:
    <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.
    Last edited by Frinavale; May 6 '10, 01:29 PM. Reason: Please post code in [doe] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    A callback is a special postback....but it's still a postback.

    When a classic postback occurs the whole page is sent to the server, and the whole page is sent back to the browser.

    When a callback occurs, the script callback doesn't redraw the whole page.

    ViewState is not updated during a callback, but it is for postback.

    Comment

    • qwedster
      New Member
      • Jul 2008
      • 24

      #3
      Thanks for the reply

      Comment

      Working...