|
|
 |
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

June 4th, 2006, 12:12 AM
|
|
Registered User
|
|
Join Date: Jun 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

July 2nd, 2006, 12:44 PM
|
|
Registered User
|
|
Join Date: Jul 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

March 1st, 2007, 11:53 PM
|
|
Authorized User
|
|
Join Date: Feb 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm having the same problem with this one using the C# code.
|

March 3rd, 2007, 10:47 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Location: , , .
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.cs" 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;
}
}
|

July 10th, 2008, 06:16 PM
|
|
Registered User
|
|
Join Date: Jul 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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();
}
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |