a new tour, Ramones at Gómez

June 8, 2007

how to use CallbackEventHandler, the example

Filed under: code lines

<%@ Page Language="C#" %>
<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

<!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>Untitled Page</title>
    <script runat="server" >
        string result = string.Empty;
    // Define method that processes the callbacks on server.
     //receive the argument transfered from client-side
    public void RaiseCallbackEvent(String eventArgument)
    {
        result = eventArgument + " and more";
    }

    // Define method that returns callback result.
    // return the result to the client-side function which is specified in the GetCallbackEventReference
    public string GetCallbackResult()
    {
        return result;
    }
    </script>
   
    <script language="javascript" type="text/javascript">
   
    // the <% %> code will becomes a js function when the page is displayed at the browser.
    function jscall(arg,context)
    {
           <%= Page.ClientScript.GetCallbackEventReference(this, "arg", "receiveFunction", "context")%>;
    }
   
    // result from the server-side is passed to the "result" argument
    function receiveFunction(result,context)
    {
       form1.test.value=result ;
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
<input name="test" value=’I love kerry more’  size="100"/>
<input type="button" value="call" onclick="jscall(form1.test.value,’none’)" />
    </form>
</body>
</html>

Comments »

The URI to TrackBack this entry is: http://ramones.blogsome.com/2007/06/08/how-to-use-callbackeventhandler-the-example/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Jay of onefinejay.com