locked
Can get Sys.Data.AdoNetDataContext work !!! RRS feed

  • Question

  • I have a simpel ado.net service pointing towards Northwind DB. I tried to access data using AJAX 4 preview. But I got Sys.Data.Adodatacontext is null or not an object from Client, Javascript.I'm using regular AJAX ASPX web form.
    Error is happening at the line where I'm trying to instantiate ADONETDataService object

    var dataContext = new Sys.Data.AdoNetDataContext();


    Here is the complete client code.

    <%

    @ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DemoApp.WebForm1" %>

     

    <!

    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>Untitled Page</title>

     

    <link href="default.css" rel="stylesheet" type="text/css" />

     

     

     

    <script type="text/javascript" >

     

     

    function pageInit() {

     

    var dataContext = new Sys.Data.AdoNetDataContext();

    dataContext.set_serviceUri(

    "http://localhost/demoapp/SampleService.svc");

     

    var template = $create(

    Sys.UI.DataView,

    {

    dataProvider: dataContext,

    query:

    "Customers",

    queryParameters: { $top: 10 }

    },

     

    null,

     

    null,

    $get(

    "customers-template")

    );

    }

     

     

    </script>

     

    </

    head>

    <

    body xmlns:sys="javascript:Sys"

     

    xmlns:dataview="javascript: Sys.UI.DataView"

     

    sys:activate="*"

     

    >

     

    <form id="form1" runat="server">

     

    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false" EnableHistory="true">

     

     

    <Scripts>

     

    <asp:ScriptReference Path="~/scripts/MicrosoftAjax.debug.js" ScriptMode="Debug" />

     

    <asp:ScriptReference Path="~/scripts/MicrosoftAjaxTemplates.debug.js" ScriptMode="Debug" />

     

    <asp:ScriptReference Path="~/scripts/MicrosoftAjaxAdoNet.debug.js" ScriptMode="Debug" />

     

    </Scripts>

     

    </asp:ScriptManager>

     

    <script type="text/javascript">

    Sys.Application.add_init(pageInit);

     

    </script>

     

    <div>

     

    <table>

     

    <thead>

     

    <tr>

     

    <td>Customer ID</td>

     

    <td>Contact Name</td>

     

    </tr>

     

    </thead>

     

    <tbody id="customers-template" class="sys-template">

     

    <tr>

     

    <td>{{CustomerID}}</td>

     

    <td>{{ContactName}}</td>

     

    </tr>

     

    </tbody>

     

    </table>

     

    </div>

     

     

    </form>

    </

    body>

    </

    html>

     

    Monday, April 27, 2009 8:00 PM

Answers

All replies

  • Hi Kali,
     Please check if the scripts are being downloaded in a http debugger like Fiddler ( www.fiddlertool.com
     and also try changing the add_init call to an add_load call

      Sys.Application.add_load(pageInit)

    http://msdn.microsoft.com/en-us/library/bb383829.aspx
    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Monday, April 27, 2009 8:21 PM
    Moderator
  • Thanks for your reply.

    I tried with Filddler in two ways.

    1) Attached Fiddler to Browser . I did not see any fiddler entries to my web request.
    2) tried Using Fiddler Request Builder. I saw HTTP response 200.

    I know some Microsoft AJAX ADonetservice script is not loaded.
    I alsro tried without scriptmanager, loading directly from htm file.

    Do you have any sample, calling ADO Netservice from Ajax 4.0 Preview?

    Appreciate your help.
    Monday, April 27, 2009 8:35 PM
  • Politan's blog has a lot of interesting samples .
    Here's a relevant one :

    http://politian.wordpress.com/2009/04/04/accessing-an-adonet-data-service-with-aspnet-ajax-part-i/

    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Monday, April 27, 2009 8:59 PM
    Moderator
  • Looks like you're missing a reference to MicrosoftAjaxDataContext.debug.js.  That was my problem anyway.
    http://rapidapplicationdevelopment.blogspot.com
    Tuesday, March 16, 2010 8:56 PM