-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: Swapnil_B1
Message 1 in Discussion

 
Client Call Back in ASP.NET 2.0 
ASP.NET 2.0 includes a new Client Callback feature that enables you to retrieve 
page values and populate them to an already-generated page with out 
reconstructing page. This makes it possible to use on a page with out going 
through the entire post back cycle; that means you can update your pages 
without completely redrawing the page. End users will not see the page flicker 
and reposition, and the pages will have a flow of a thick client application. 
It is an interesting feature that allows invoking server side code from Client 
side JavaScript using XmlHTTP. 
Postback and Callback 
Before we appreciate the feature of Callback, let's see how current Postback 
feature in a typical ASP.NET page works. 
In a normal Postback situation, when any page event is triggered on ASP.NET 
page, a HTTP post request will be sent to web server, which then processes the 
request with the IPostbackEventHandler and runs the request through a series of 
page events. These events include loading the state (ViewState), processing 
data, processing Postback events and finally rendering the page to be 
interpreted by the consuming browser. 
This process completely reloads the page in the browser, which is what causes 
the flicker and the realignment to the top of the page. 
But in a Client call back situation, any page event is triggered on ASP.NET 
page; it causes the event to be posted to a script event handler (a JavaScript 
function) that sends off an asynchronous request to the web server for 
processing. ICallbackEventHandler runs the request through a pipeline similar 
to what is used with the Postback- but you notice that some of the larger steps 
(such as rendering the page) are excluded from the process chain. After the 
information is loaded, the result is returned to the script callback object. 
The script code then pushes this data into the web page using JavaScript's 
capabilities to do this without refreshing the page. 
Let's see an example to see how Callback feature works. Following page will 
generate Current date when end user clicks the button on the form, the callback 
service is initiated and current date is populated into the textbox.  
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 
Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
 
<html xmlns="http://www.w3.org/1999/xhtml"; >
<head runat="server">
    <title>Client Callback</title>
    <script type="text/javascript" >
    function GetDate()
    {
    UseCallback();
    }
    function GetDateFromServer(TextBox1, context)
    {
    document.forms[0].TextBox1.value= TextBox1;
    }
     </script>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Button1" type="button" onclick="GetDate()" value="Get Date" 
/>  
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html><o:p></o:p> 
Partial Class _Default
    Inherits System.Web.UI.Page
    Implements System.Web.UI.ICallbackEventHandler
    Dim _callbackResult As String = Nothing
 
 
    Public Function GetCallbackResult() As String Implements 
System.Web.UI.ICallbackEventHandler.GetCallbackResult
        Return _callbackResult
    End Function
 
    Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements 
System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
        _callbackResult = Now.ToString()
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles Me.Load
        Dim cbReference As String = 
Page.ClientScript.GetCallbackEventReference(Me, "arg", "GetDateFromServer", 
"context")
        Dim cbScript As String = "function UseCallback(arg,context)" & _
        "{" & cbReference & ";" & "}"
        Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), 
"UseCallback", cbScript, True)
    End Sub
 
End Class 
 
Swapnil (Swaps) 
http://swapsnet.spaces.live.com/

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to