Skip to main content

Microsoft Ajax Client Template

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>Ajax Client Side Template</title>

    <script src="Scripts/MicrosoftAjax.debug.js" type="text/javascript"></script>

    <script src="Scripts/MicrosoftAjaxTemplates.debug.js" type="text/javascript"></script>

    <script src="Scripts/MicrosoftAjaxAdoNet.debug.js" type="text/javascript"></script>

    <style type="text/css">
        .sys-template
        {
            display: none;
        }
    </style>

    <script type="text/javascript">
        function LoadData() {
            $create(Sys.UI.DataView, {
                dataProvider: "Service.svc",
                fetchOperation: "GetData",
                autoFetch: "true"
            }, {}, {}, $get("tblProduct"));
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <input type="button" id="btnFetch" value="Display Data" onclick="LoadData();" />
    <table id="tblProduct" class="sys-template" border="1">
        <tr>
            <td>
                {{ProductID}}
            </td>
            <td>
                {{ProductName}}
            </td>
        </tr>
    </table>
    </form>
</body>
</html>
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Collections.Generic;
[DataContract]
public class Product
{
    [DataMember]
    public string ProductName;
    [DataMember]
    public int ProductID;
}
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service
{
    // Add [WebGet] attribute to use HTTP GET
    [OperationContract]
    public List<Product> GetData()
    {
        List<Product> ret = new List<Product>();

        for (int i = 0; i < 10; i++)
        {
            ret.Add(new Product {ProductName = "Product " + i.ToString(), ProductID = i });
        }
        return ret;
    }

    
}
download

Comments

Popular posts from this blog