Wednesday, December 24, 2008

ASP.NET Ajax : Templating


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="CSAstoria.index" %>

<!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 runat="server">
    <title></title>
    <style type="text/css">
        .sys-template
        {
            display: none;
        }
    </style>

    <script type="text/javascript" language="javascript">
        var ds;
        var array;
        function pageLoad() {
            ds = new Sys.Data.AdoNetServiceProxy("Northwind.svc");
            ds.query("Products", cbSuccess, cbFailure, null, null);
        }

        function cbSuccess(result, context, opertation) {
            var dataView = new Sys.UI.DataView(document.getElementById("listTemplate"));
            dataView.set_data(result);
            dataView.updated()
        }

        function cbFailure(error, context, operation) {
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/MicrosoftAjaxAdoNet.js" />
            <asp:ScriptReference Path="~/MicrosoftAjaxTemplates.js" />
        </Scripts>
    </asp:ScriptManager>
    <div id="listTemplate" class="sys-template">
        <ul>
            <li>{{ ProductID }} - {{ ProductName }} </li>
        </ul>
    </div>
    </form>
</body>
</html>

ADO Data Services : Service Operations and Interceptors

ADO Data Services (aka Astoria) is a very powerful framework, which enables to expose easyly data and methods on the web.
Here is a document which illustrate how to create new methods or intercept calling methods.

http://msdn.microsoft.com/en-gb/library/cc668788.aspx