10.02.2014 Views

Beginning Ajax With ASP.NET (2006).pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Debugging<br />

TestFiddler.aspx.cs — Code-Beside file<br />

using System;<br />

using System.Data;<br />

using System.Configuration;<br />

using System.Collections;<br />

using System.Web;<br />

using System.Web.Security;<br />

using System.Web.UI;<br />

using System.Web.UI.WebControls;<br />

using System.Web.UI.WebControls.WebParts;<br />

using System.Web.UI.HtmlControls;<br />

public partial class FiddlerExamples_TestFiddler : System.Web.UI.Page,<br />

ICallbackEventHandler<br />

{<br />

protected void Page_Load(object sender, EventArgs e)<br />

{<br />

string js = Page.ClientScript.GetCallbackEventReference(this, “arg”,<br />

“OnCallComplete”, “ctx”, true);<br />

string jsFunction = “function DoCallback(arg,ctx) { “ + js + “ } “;<br />

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), “Callback”,<br />

jsFunction,true);<br />

}<br />

#region ICallbackEventHandler Members<br />

public string GetCallbackResult()<br />

{<br />

System.Threading.Thread.Sleep(2000);<br />

string[] dataToReturn = new string[] { “Data1”, “DataPart2”, “SomeData3” };<br />

// return a hardcoded string array as a single string<br />

return string.Join(“;”, dataToReturn);<br />

}<br />

public void RaiseCallbackEvent(string eventArgument)<br />

{<br />

// Do nothing here<br />

}<br />

}<br />

#endregion<br />

Ensure that the application runs by right-clicking on the modified page with the mouse and selecting<br />

View in Browser. A simple web page should be displayed with a single button labeled Do Async<br />

Callback. Clicking the button with the mouse should result in a 2-second delay and then three alert<br />

boxes displaying the returned data values of Data1, DataPart2, and SomeData3.<br />

This page is obviously not very complex, but it does utilize an asynchronous postback to execute a<br />

server-side method and retrieve some data for display.<br />

Now click on the Fiddler icon shown previously or access the Fiddler tool by selecting the Tools➪Fiddler<br />

menu option.<br />

355

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!