Wrox Programmer Forums
|
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2006, 11:12 PM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default charpter 4 callback feature

does anyone know how to use this feature?

i have followed the listing 4-14, and modified the codes based on the changes to ICallbackEventHandler class in asp.net 2.0 final release, but i got "UseCallback" is not defined when i access the aspx page. it complains the UseCallback() javascript function, which is created in the code-behind, is not defined. do i need to setup anything to enable this callback feature in 2.0? please help.



 
Old July 2nd, 2006, 11:44 AM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I believe 'UseCallback' is an arbitrary name. You do have to define it yourself. On page 124, the book seems to define the function in this chunk of code:

Code:
string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "GetRandomNumberFromServer", "context");
string cbScript = "function UseCallback(arg, context)" + 
  "{" + cbReference + ";" + "}";

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallback", cbScript, true);
And remember JavaScript is case sensitive; "UseCallback" and "UseCallBack" are different.
 
Old March 1st, 2007, 11:53 PM
Authorized User
 
Join Date: Feb 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having the same problem with this one using the C# code.

 
Old March 3rd, 2007, 10:47 PM
Authorized User
 
Join Date: Sep 2006
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi does your code works at all?
or you simply want to know more about the CallBack feature?
This one works fine.
In a case you still need a working one, copy paste it to your project.

//---------------------------------------------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.c s" 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" id ="Head1">
    <title>Listing 4-14 CallBackPage</title>


    <script type ="text/javascript">

    function GetNumber()
    {
     UseCallback(); // Don't Make a Typo here :)
    }

    function GetRandomNumberFromServer(TextBox1, context)
    {
     document.forms[0].TextBox1.value = TextBox1;
    }

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
         <input id ="Button1" type ="button" value ="Get Random Number" onclick ="GetNumber()" />
         <br />
         <br />
         <asp:TextBox ID ="TextBox1" runat ="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>

================================================== ===========================
c# Code behind

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page, //Dont't forget the Comma here,
System.Web.UI.ICallbackEventHandler
{
    private string _callbackResult = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        string cbReference = Page.ClientScript.GetCallbackEventReference(this,
         "arg", "GetRandomNumberFromServer", "context");
        string cbScript = "function UseCallback(arg, context)" +
         "{" + cbReference + ";" + "}";

        Page.ClientScript.RegisterClientScriptBlock(this.G etType(),
         "UseCallback", cbScript, true);
    }

    public void RaiseCallbackEvent(string eventArg)
    {
        Random rnd = new Random();
        _callbackResult = rnd.Next().ToString();
    }

    public string GetCallbackResult()
    {
        return _callbackResult;
    }
}
 
Old July 10th, 2008, 05:16 PM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the source code but that did not work without fully qualifying the two callback methods with ICallbackEventHandler.



   string ICallbackEventHandler.GetCallbackResult()
    {
        //throw new Exception("The method or operation is not implemented.");
        return _callbackResult;
    }

    void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
    {
        Random rnd = new Random();
        _callbackResult = rnd.Next().ToString();
    }






Similar Threads
Thread Thread Starter Forum Replies Last Post
callback implementation aranjan ASP.NET 2.0 Basics 1 August 20th, 2007 09:46 PM
Callback in 3 DropDownLists Paula222 ASP.NET 2.0 Professional 3 December 13th, 2006 08:53 AM
Worldpay Callback Script Countach1976 PHP Databases 3 January 1st, 2005 10:36 AM
Remoting.Callback sample mikhail BOOK: Professional C#, 2nd and 3rd Editions 0 July 11th, 2003 04:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.