views:

282

answers:

1

I am playing around with MVC 2 a bit and was trying to hook up a text box to the Microsoft AjaxToolkit AutoCompleteBehavior.

and I cannot get the java script to fire. Originally I thought that my scrpt references were wrong but have pointed the scripts to the CDN versions.

it looks like I never enter the Sys.Application.add_init(function () { where I create my object.

could anyone see if I am missing something simple. or am I just doing it wrong?

    <script src="http://ajax.microsoft.com/ajax/act/40412/extended/ExtenderBase/BaseScripts.js" type="text/javascript"></script>
  <script src="http://ajax.microsoft.com/ajax/act/40412/extended/Common/Common.js" type="text/javascript"></script>
  <script src="http://ajax.microsoft.com/ajax/act/40412/extended/Animation/Animations.js" type="text/javascript"></script>
  <script src="http://ajax.microsoft.com/ajax/act/40412/extended/Animation/AnimationBehavior.js" type="text/javascript"></script>
  <script src="http://ajax.microsoft.com/ajax/act/40412/extended/PopupExtender/PopupBehavior.js" type="text/javascript"></script>
  <script src="http://ajax.microsoft.com/ajax/act/40412/extended/Compat/Timer/Timer.js" type="text/javascript"></script>
  <script src="http://ajax.microsoft.com/ajax/act/40412/extended/AutoComplete/AutoCompleteBehavior.js" type="text/javascript"></script>

  <script type="text/javascript">
   Sys.Application.add_init(function () {
    $create(Sys.Extended.UI.AutoCompleteBehavior
    , { "delimiterCharacters": ""
    , "serviceMethod": "ProductNameSearch"
    , "servicePath": "/ProductService.asmx"
    , "minimumPrefixLength": 1
    }
    , null
    , null
    , $get("query"));
   });       



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

 <%using (Ajax.BeginForm("ProductSearchAC"
     , new AjaxOptions { UpdateTargetId = "results" }))
  { %>
    <%=Html.TextBox("query",null, new {size=40}) %>
    <input type="submit" />
   <%} %>

 <div id="results">


 </div>
+1  A: 

looks like the only thing missing was a script reference to MicrosoftAjax.js before any of the AjaxToolKit references

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

i have now updated my code with the latest AjaxToolKit javascripts and it all works fine. hooray!!

    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/ExtenderBase/BaseScripts.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/Common/Common.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/Animation/Animations.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/PopupExtender/PopupBehavior.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/Animation/AnimationBehavior.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/Compat/Timer/Timer.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/AutoComplete/AutoCompleteBehavior.js" type="text/javascript"></script>

A Thanks to Stephen Walther who has some very nice tutorials regarding AjaxToolkit and MVC http://stephenwalther.com/blog/archive/2008/08/24/asp-net-mvc-tip-37-create-an-auto-complete-text-field.aspx check them out.

ftnilsson