473,508 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5752
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
1390
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
567
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
1141
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
3400
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
2494
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
7393
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
955
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
2001
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
1438
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
771
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
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
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
7405
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...
1
7066
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
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.