<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title>ASP.NET AJAX</title>

  <script language="JavaScript" type="text/javascript">
  function clearList() {
    $get("Results").innerHTML = "";
  }

  function Search() {
    var query = new Sys.Preview.UI.TextBox($get('Query'))
    $get("Button").disabled = true;
    clearList();
    OReilly.AspNetAJAX.Amazon.SearchXslt(
      { "query": query.get_text() },
      callComplete, callTimeout, callError
    );
  }
  
  function callComplete(result)  {
    $get("Results").innerHTML = result;
    $get("Button").disabled = false;
  }
  function callTimeout(result) {
    window.alert("Error! " + result.get_message());
    $get("Button").disabled = false;
  }
  function callError(result) {
    window.alert("Error! " + result.get_message());
    $get("Button").disabled = false;
  }
  </script>

</head>
<body>
  <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
      <Services>
        <asp:ServiceReference Path="~/Amazon.asbx" />
      </Services>
      <Scripts>
        <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />
      </Scripts>
    </asp:ScriptManager>
    <div>
      <input type="text" id="Query" />
      <input type="button" id="Button" value="Search" onclick="Search();" />
    </div>
    <div id="Results">
    </div>
  </form>
</body>
</html>
