Listing 1
//SERVER
#region ICallbackEventHandler Members
private string _strCallbackData = null;
public void RaiseCallbackEvent(String event Argument)
{
_strCallbackData = eventArgument;
}
public string GetCallbackResult()
{
//TODO: Modify data here
return _strCallbackData + " modified at Callback " + DateTime.Now.ToString();
}
#endregion
Listing 2
//SERVER
protected void Page_Load(object sender, EventArgs e)
{
SetupAlways();
}
private void SetupAlways()
{
//setup callbacks:
string cbReference =
Page.ClientScript.GetCallbackEventReference(
this,
"arg",
"ReceiveCallback",
"context");
string callbackScript = "function CallServer
(arg, context)" + "{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(
this.GetType(),
"CallServer",
callbackScript,
true);
}
Listing 3
//CLIENT
function StartCallback()
{
//TODO: assemble the data to send to the callback
var strData = "user input data here";
CallServer(strData, "");
}
function ReceiveCallback(strReturnData)
{
//TODO: use the data that you gte back from the callback.
document.getElementById("Span1").innerHTML = strReturnData;
}
Listing 4
public class EmployeeData
{
public int Id;
public string Name;
}
Listing 5
public static object DeserializeFromXmlString(
System.Type t, string strXml)
{
// Requires namespaces:
// using System.IO;
// using System.Xml.Serialization;
XmlSerializer x = null;
StringReader sr = null;
try
{
sr = new StringReader(strXml);
x = new XmlSerializer(t);
return x.Deserialize(sr);
}
finally
{
if (sr != null)
sr.Close();
}
}
Listing 6
var strData = "<EmployeeData>"
+ "<Id>" + myID + "</Id>"
+ "<Name>" + myName + "</Name>"
+ "</EmployeeData>";
Listing 7
EmployeeData emp = (EmployeeData)Utilities.DeserializeFromXmlString(
typeof(EmployeeData),
strXml);