473,395 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error using ICallbackEventHandler in ASP.Net 2.0

When trying to compile (using Visual Web Developer 2005 Express Beta;
frameworkv2.0.50215 ) the source code below I get errors (listed below due to
the use of ICallBackEventHandler. Ultimately I want to use a callback from
the client side to update webcontrols based on user input without using
postback.

I am seeking a way to stop the compile errors.

using System;
using System.Data;
using System.Configuration;
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 : ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{

}

public string RaiseCallbackEvent(string eventArgument) { }
}

I get these errors
1. 'ASP.Index_aspx.FrameworkInitialize()': no suitable method found to
override c:\WINNT\Microsoft.NET\Framework\v2.0.50215\Tempor ary ASP.NET
Files\callback\02ec0c94\71251b27\tvquf1zy.0.cs

2. 'ASP.Index_aspx.GetTypeHashCode()': no suitable method found to
override c:\WINNT\Microsoft.NET\Framework\v2.0.50215\Tempor ary ASP.NET
Files\callback\02ec0c94\71251b27\tvquf1zy.0.cs

I added the code
protected virtual void FrameworkInitialize()
{

}

protected override void GetTypeHashCode()
{

}

but then I get an error about the access level of GetTypeHashCode
Error 1 'ASP.Default_aspx.GetTypeHashCode()': cannot change access modifiers
when overriding 'protected' inherited member
'_Default.GetTypeHashCode()' c:\WINNT\Microsoft.NET\Framework\v2.0.50215\Tempor ary ASP.NET Files\callback\02ec0c94\71251b27\zqawgoe7.0.cs

Nov 22 '05 #1
1 5739
Okay, I think I have this one figured out. It seems that some things changed
in the 2.0 DotNet framework with Beta 2. All of the "Client Callback"
samples I found on the web didn't seem to work. As a starting point, I ended
up using a bit of the code found in the article found here:
http://www.devx.com/dotnet/Article/20239/0/page/2. After trying a lot of
different things, I boiled it down to a simple example that I was able to
get to work. I'm using Visual Studio 2005 (Beta 2) with code-behind pages.
Here is the text from my "Test.aspx" page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs"
Inherits="Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Client Callback Test</title>
<script type="text/javascript">
function DoSomething(){
TheText =
document.getElementById("TextBox1").getAttribute(" value");
CallServer(TheText, "'DoSomething' was called.");
}

function CallBackHandler(result,context)
{
document.getElementById("TextBox2").innerText = "CallBackHandler
Invoked. \nResult: " + result + "\nContext:" + context;

}
function ErrorCallBack(result,context)
{
alert("Error occurred : " + result);
}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="button"
onclick="DoSomething()" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"
Height="140px" Width="312px"></asp:TextBox>
</div>
</form>
</body>
</html>

Here's the text from my "Test.aspx.cs" file:

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 Test : System.Web.UI.Page, ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
string bScript = ClientScript.GetCallbackEventReference(this,
"myArg", "CallBackHandler", "myContext", "ErrorCallBack", true);
//create the Javascriptfunction that makes the actual server
call.
string sb = "function CallServer(myArg,myContext)\n{\n" +
bScript + "\n}";
//Register the clientscript.
Page.ClientScript.RegisterClientScriptBlock(this.G etType(),
"CallServer", sb.ToString(), true);
}

}
public String RaiseCallbackEvent(String eventArgument)
{
int myInt = int.Parse(eventArgument.Trim()) * 2;
return "The new value is " + myInt.ToString();
}
}

The first important thing to note is that the partial class inherits the
Web.UI.Page class AND implements the ICallbackEventHandler interface. I
think this takes care of the "...no suitable interface found..." type
errors. Then, it looks like the "GetCallbackEventReference" method has been
rolled into the ClientScript object, which is the "Page" implementation of
the "ClientScriptManager" class, so it must be called as such.

The basic explanation of how my example works is: When the user clicks on
"Button1," the javascript function "DoSomething" is called. The
"DoSomething" function grabs the value from "TextBox1" and passes it off in
the call to the server, by making a call to the "CallServer" function. The
actual javascript function "CallServer" will have already been created
during the initial Page_Load execution and inserted into the aspx page via
the "RegisterClientScriptBlock" method (you'll note there is also some
additional auto-generated code created at this time that is inserted into
the client aspx page that is needed to do the callback). So, that
"CallServer" function on the client invokes the "RaiseCallbackEvent" method
on the server, which attempts to convert the string into an integer,
multiply it by two, and return the value as part of a new string. If the
initial value is an integer, it does the calculation and passes back the new
string back to the client, invoking the execution of the JavaScript
"CallBackHandler" function, which displays the various lines of text, part
of which came from the server. If the initial value isn't an integer, the
server throws an exception and the client JavaScript function
"ErrorCallBack" is executed instead. There is only one string that gets
passed from the client to the server (as a parameter in the
"RaiseCallbackEvent" method), and the second "Context" parameter is
something that stays unchanged (by the server) on the client side, which can
be useful to determine where in the code on the client side the callback was
made.

Well, anyway, hope this is helpful. I know I was glad to finally get this
much-celebrated, but as of yet, not terribly well-documented new feature to
work.

Troy

"Mike" <si***@newsgroups.nospam> wrote in message
news:98**********************************@microsof t.com...
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike | last post by:
When trying to compile in Visual Web Developer 2005 express beta (framework version )the source code using System; using System.Web.UI; using System.Web.UI.WebControls; using...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
1
by: JimGreen | last post by:
I recently installed Release Candidate of VS2005 and I am not sure what the hell is the problem but ICallbackEventHandler definition on my machine looks like this: public interface...
2
by: Anand | last post by:
Hi Season Greetings, I'm trying to implement client call backs in my page. i'm using user controls (composite controls) and these are placed in my master page. I'm implementing...
2
by: Alani | last post by:
Hello All, I'm a new ASP.NET programmer and I want to create a custom control consist of two properties (Number1) and (Number2) and both of them are integers and default value = 0, now I'm...
3
by: Martin | last post by:
Hi, I have an aspx page with two dropdownlist controls. I update the options in the second ddl based on selection made in the first. I do this with the ICallbackEventHandler interface, as per...
0
by: Slim | last post by:
I made a page today that uses ICallbackEventHandler. I got to work, but with problems. 1. it is slow, it does not seem any faster than reloading the page. 2. the first time I fire the event it...
1
by: Ben Schumacher | last post by:
I have a page that implements ICallbackEventHandler. I'm trying to accomplish auto saving a page everytime the user navigates away from the page. To initialize the callback, I fire the onunload...
0
by: =?Utf-8?B?TG93bGFuZGVy?= | last post by:
Hello, I've built a web application that uses client script callbacks. It is used on a large network with a large variety of user OSes and IE versions. It was tested on IE 6 on different setups...
0
by: dcrawford | last post by:
Hi All I have an Icallbackeventhandler working which updates a multiselect list box by removing the current items and then rebuilding the list with either terminated or active employees. The...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.