View Single Post
  #1 (permalink)  
Old November 17th, 2009, 04:53 AM
elwappo elwappo is offline
Authorized User
Points: 192, Level: 3
Points: 192, Level: 3 Points: 192, Level: 3 Points: 192, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2006
Location: God's country , United Kingdom.
Posts: 41
Thanks: 1
Thanked 0 Times in 0 Posts
Default ICallbackEventHandler.RaiseCallbackEvent

Hi all,
I've been looking into the MSDN exampe of how to implement a simple client/server callback, which involves implementing the ICallbackEventHandler interface, which works fine.

The example shows that you can pass an extra context value with the partial postback, and you can also pick it up on the return client callback function. Yup, understood and I can see how that works.

However, the implementation of "RaiseCallbackEvent" function on the server side accepts only one parameter and there seems no way of accessing the context value in the code behind, and have the ability to manipulate if needed?

Here's the example I've been looking at:

1. A button fires a javascript function:
<button type="button" onclick="LookUpStock()">Look Up Stock</button>

2. The javascript function:
<script type="text/ecmascript">
function LookUpStock()
var lb = document.getElementById("ListBox1");
var product = lb.options[lb.selectedIndex].text;
CallServer(product, "mycontextval");

function ReceiveServerData(rValue,contextvalue)
document.getElementById("ResultsSpan").innerHTML = rValue + ' ' + contextvalue;

3. The Call Server Javascript call which fires the postback and contains the parameters and return client callback function:
<script type="text/javascript">
function CallServer(arg, context){ WebForm_DoCallback('__Page',arg,ReceiveServerData, context,null,false);}//]]>

You can see the "arg" AND "context" values in the WebForm_DoCallback function, but you cannot seem to access it on the server as the RaiseCallbackEvent event signature has only one string parameter, and handles the in coming "arg" value only:

void ICallbackEventHandler.RaiseCallbackEvent(String eventArgument)
// code here

Does anyone know how you can access the context value in the code behind? As it seems to be sent to the server. I can see how everything hangs together, and how the calls are working, just can't work out how to to access the context value server side!

Any help would be appreciated...

Last edited by elwappo; November 17th, 2009 at 04:57 AM..