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.

Chapter 6<br />

Here you can see that the exception message has been displayed, in addition to the result of the<br />

GetCallbackResult method. Both of the messages have been aggregated together, but separated by<br />

a pipe (|) character. What is happening is that the asynchronous client script framework is still calling<br />

both of the required methods of the ICallbackEventHandler interface, even though one of the methods<br />

generated an exception. The fact that one of the methods generates an exception does not preclude<br />

the execution of the other method. This is an important point because the GetCallbackResult method<br />

needs to be aware of any errors that have occurred during the execution of the RaiseCallbackEvent<br />

method and not blindly execute assuming that if execution reaches that method, then all previous program<br />

execution has occurred without error.<br />

Dealing with Complex Data<br />

In the previous examples, the result of the asynchronous callback server-side methods has been only a<br />

simple singular textual string result. The needs of applications are many, and the need to deal with more<br />

complex data is a common scenario, particularly where there is a need to return more than one result.<br />

As an example, suppose that you wanted to load the values of a drop-down list from a potentially longrunning<br />

server-side query or operation. There might be many items to load into the drop-down list, and<br />

each item will typically have a value associated with it, which is returned when the user selects a particular<br />

option from the drop-down list.<br />

To illustrate this scenario, the following web page contains a simple drop-down list and a span area that<br />

will contain the selected value from the drop-down list:<br />

<br />

<br />

<br />

<br />

Asynchronous Drop Down List Example<br />

<br />

function LoadListItems()<br />

{<br />

}<br />

<br />

<br />

<br />

<br />

<br />

<br />

(Loading values from the Server)<br />

<br />

<br />

<br />

144

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

Saved successfully!

Ooh no, something went wrong!