Using the Callback control framework
Ryan Olson of the Web ADF development team contributed the following code
sample that demonstrates how to use the callback framework from within the ESRI
Web ADF for the Microsoft .NET Framework.
This control is very useful for testing things during the context of a
callback. When called, it fires a server-side event in the context of a
page callback so that you can attach to that event at design time or
programmatically and act on the event. You can return
"javascript" as the event argument to execute a JavaScript function
or you can refresh the contents of a non-AJAX-enabled control (like the
Gridview) without having to write a line of JavaScript.
The code is extremely simple and yet it shows how to use the Web ADF
CallbackResults and the WebControl base class Callback implementation.
Here is some
sample code to execute some javascript
protected void CallbackButton1_Clicked(object sender, EventArgs
args)
{
CallbackButton1.CallbackResults.Add(new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(CallbackButton1, "javascript", "alert('hello');"));
}
Here is some
sample code to refresh a control that doesn’t inherit from our webcontrols with
the CallbackButton (like a gridview):
protected void CallbackButton1_Clicked(object sender, EventArgs
args)
{
CallbackButton1.CallbackResults.Add(RefreshControlHtml(GridView1));
}
private CallbackResult RefreshControlHtml(Control
control)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(sw);
control.RenderControl(writer);
string htmlContent =
sw.ToString();
sw.Close();
return new CallbackResult(control, "content",
htmlContent);
}
Try out a sample application illustrating the usage here: http://serverx.esri.com/callbackbuttonSample/