<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Damian&#039;s Blog &#187; MVC</title>
	<atom:link href="http://damianblog.com/category/mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://damianblog.com</link>
	<description>.NET from Geneva, Switzerland</description>
	<lastBuildDate>Fri, 30 Sep 2011 23:25:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ASP.NET MVC with the AJAX Control Toolkit: automatically getting control dependencies</title>
		<link>http://damianblog.com/2008/10/22/mvc-control-toolkit-dependencies/</link>
		<comments>http://damianblog.com/2008/10/22/mvc-control-toolkit-dependencies/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 16:12:18 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://damianblog.com/2008/10/22/aspnet-mvc-with-the-ajax-control-toolkit-automatically-getting-control-dependencies/</guid>
		<description><![CDATA[[Edited 23rd Oct to compress returned JavaScript] I recently wrote a blog post showing how you can use controls from the AJAX Control Toolkit in ASP.NET MVC applications, specifically the ListSearchExtender.&#160; Stephen Walther also wrote one on using the Calendar control here. One thing that bugged me was that it was painful to find out [...]]]></description>
			<content:encoded><![CDATA[<p>[Edited 23rd Oct to compress returned JavaScript]</p>
<p>I recently wrote a <a href="http://damianblog.com/2008/09/07/using-aspnet-mvc-and-the-ajax-control-toolkit/">blog post</a> showing how you can use controls from the AJAX Control Toolkit in ASP.NET MVC applications, specifically the ListSearchExtender.&#160; Stephen Walther also wrote one on using the Calendar control <a href="http://weblogs.asp.net/stephenwalther/archive/2008/08/22/asp-net-mvc-tip-36-create-a-popup-calendar-helper.aspx">here</a>.</p>
<p>One thing that bugged me was that it was painful to find out what scripts a particular control depended on, so that they could be included in the JavaScript used to initialize a control.</p>
<p>I decided to create a simple MVC Controller/View that would return back all the JavaScript required for any particular ASP.NET AJAX Control Toolkit control.</p>
<p>This is the old code for using the ListSearchExtender in an ASP.NET MVC View:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 500px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; height: 426px; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; height: 240px; background-color: #f4f4f4; border-bottom-style: none">&lt;select id=<span style="color: #006080">&quot;Countries&quot;</span>&gt;
    &lt;option&gt;Switzerland&lt;/option&gt;
    &lt;option&gt;United Kindom&lt;/option&gt;
    &lt;option&gt;United States&lt;/option&gt;
&lt;/select&gt;

&lt;script src=<span style="color: #006080">&quot;/Scripts/MicrosoftAjax.debug.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.Common.Common.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.ExtenderBase.BaseScripts.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.DynamicPopulate.DynamicPopulateBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.Compat.Timer.Timer.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.Animation.Animations.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.Animation.AnimationBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.PopupExtender.PopupBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.PopupControl.PopupControlBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
&lt;script src=<span style="color: #006080">&quot;/Scripts/AjaxControlToolkit.ListSearch.ListSearchBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;

&lt;script type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;
Sys.Application.initialize();
Sys.Application.add_init(<span style="color: #0000ff">function</span>() {
    $create(AjaxControlToolkit.ListSearchBehavior,
        { <span style="color: #006080">&quot;id&quot;</span>: <span style="color: #006080">&quot;ListBox1_ListSearchExtender&quot;</span> },
        <span style="color: #0000ff">null</span>, <span style="color: #0000ff">null</span>, $get(<span style="color: #006080">&quot;Countries&quot;</span>));
});
&lt;/script&gt;</pre>
</div>
<p>This is the new code to pull in the dependencies:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 500px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; height: 323px; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; height: 304px; background-color: #f4f4f4; border-bottom-style: none">&lt;select id=<span style="color: #006080">&quot;Countries&quot;</span>&gt;
    &lt;option&gt;Switzerland&lt;/option&gt;
    &lt;option&gt;United Kindom&lt;/option&gt;
    &lt;option&gt;United States&lt;/option&gt;
&lt;/select&gt;

<strong>&lt;script src=<span style="color: #006080">&quot;/ControlDependencies/Get?extenderTypeName=AjaxControlToolkit.ListSearchExtender&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;
</strong>
&lt;script type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;
Sys.Application.initialize();
Sys.Application.add_init(<span style="color: #0000ff">function</span>() {
    $create(AjaxControlToolkit.ListSearchBehavior,
        { <span style="color: #006080">&quot;id&quot;</span>: <span style="color: #006080">&quot;ListBox1_ListSearchExtender&quot;</span> },
        <span style="color: #0000ff">null</span>, <span style="color: #0000ff">null</span>, $get(<span style="color: #006080">&quot;Countries&quot;</span>));
});
&lt;/script&gt;</pre>
</div>
<p>You'll see that all the individual script includes have been replaced by a single call to the Get action on the <strong>ControlDependencies</strong> controller. </p>
<p>This is the source to the controller:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2000px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Collections.Generic;
<span style="color: #0000ff">using</span> System.Reflection;
<span style="color: #0000ff">using</span> System.Web.Mvc;
<span style="color: #0000ff">using</span> AjaxControlToolkit;

<span style="color: #0000ff">namespace</span> TestDependencies.Controllers {
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> ControlDependenciesController : Controller {
    <span style="color: #0000ff">readonly</span> Assembly toolkitAssembly =
        <span style="color: #0000ff">typeof</span>(AjaxControlToolkit.Utility).Assembly;

    [OutputCache(VaryByParam = <span style="color: #006080">&quot;extenderTypeName&quot;</span>,
                 Duration = 86400,  <span style="color: #008000">// One day</span>
                 Location = System.Web.UI.OutputCacheLocation.Client)]
    <span style="color: #0000ff">public</span> ActionResult Get(<span style="color: #0000ff">string</span> extenderTypeName) {

        <span style="color: #0000ff">if</span> (<span style="color: #0000ff">string</span>.IsNullOrEmpty(extenderTypeName)) {
            <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> EmptyResult();
        }

        <span style="color: #008000">// Get the type representing the extender we are handling</span>
        Type extenderType = toolkitAssembly.GetType(extenderTypeName,
                                                    <span style="color: #0000ff">false</span>);
        <span style="color: #0000ff">if</span>(extenderType == <span style="color: #0000ff">null</span>) {
            <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> EmptyResult();
        }

        <span style="color: #008000">// What other extenders does this one depend on?</span>
        Stack&lt;Type&gt; dependencies = <span style="color: #0000ff">new</span> Stack&lt;Type&gt;();
        AddDependencies(extenderType, dependencies);

        <span style="color: #008000">// What scripts do those extenders require?</span>
        List&lt;<span style="color: #0000ff">string</span>&gt; scriptsToInclude = <span style="color: #0000ff">new</span> List&lt;<span style="color: #0000ff">string</span>&gt;();
        GetDependencyScripts(dependencies, scriptsToInclude);

        <span style="color: #0000ff">return</span> PartialView(scriptsToInclude);
    }

    <span style="color: #008000">// Find the types that the specified extender type depends on</span>
    <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> AddDependencies(Type extenderType,
                                Stack&lt;Type&gt; dependencies) {
        dependencies.Push(extenderType);
        Attribute[] attributes =
            Attribute.GetCustomAttributes(extenderType,
                      <span style="color: #0000ff">typeof</span>(RequiredScriptAttribute));

        <span style="color: #0000ff">foreach</span> (RequiredScriptAttribute attribute <span style="color: #0000ff">in</span> attributes) {
            AddDependencies(attribute.ExtenderType, dependencies);
        }
    }

    <span style="color: #008000">// Find the scripts used by the specified extender types</span>
    <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> GetDependencyScripts(IEnumerable&lt;Type&gt; dependencies,
                                     ICollection&lt;<span style="color: #0000ff">string</span>&gt; scripts) {
        <span style="color: #0000ff">foreach</span> (Type dependency <span style="color: #0000ff">in</span> dependencies) {
            Attribute[] attributes =
                Attribute.GetCustomAttributes(dependency,
                           <span style="color: #0000ff">typeof</span>(ClientScriptResourceAttribute));

            <span style="color: #0000ff">foreach</span> (ClientScriptResourceAttribute attribute <span style="color: #0000ff">in</span> attributes) {
                <span style="color: #0000ff">if</span> (!scripts.Contains(attribute.ResourcePath)) {
                    scripts.Add(attribute.ResourcePath);
                }
            }
        }
    }
}
}</pre>
</div>
<p>The View is a User Control that simply outputs all of the required scripts.&#160; This is the code-behind:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2500px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Collections.Generic;
<span style="color: #0000ff">using</span> System.IO;
<span style="color: #0000ff">using</span> System.IO.Compression;
<span style="color: #0000ff">using</span> System.Web.Mvc;

<span style="color: #0000ff">namespace</span> TestDependencies.Views.ControlDependencies {
  <span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> Get : ViewUserControl&lt;List&lt;<span style="color: #0000ff">string</span>&gt;&gt; {

    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> Page_Load(<span style="color: #0000ff">object</span> sender, EventArgs e) {
      Response.ContentType = <span style="color: #006080">&quot;application/x-javascript&quot;</span>;

      <span style="color: #008000">// Get compressed stream if possible</span>
      Stream outputStream = GetOutputStream();

      <span style="color: #0000ff">using</span>(StreamWriter outputWriter = <span style="color: #0000ff">new</span> StreamWriter(outputStream)) {

        <span style="color: #008000">// Standard AJAX library</span>
        <span style="color: #0000ff">string</span> script = File.ReadAllText(
                              MapPath(<span style="color: #006080">&quot;/Scripts/MicrosoftAjax.js&quot;</span>));
        outputWriter.WriteLine(script);

        <span style="color: #008000">// Required scripts</span>
        <span style="color: #0000ff">foreach</span>(<span style="color: #0000ff">string</span> scriptPath <span style="color: #0000ff">in</span> ViewData.Model) {
          script = File.ReadAllText(MapPath(<span style="color: #006080">&quot;/Scripts/&quot;</span> + scriptPath));
          outputWriter.WriteLine(script);
        }

      }
      Response.End();
    }

    <span style="color: #008000">// Compress scripts if possible -- stolen from ToolkitScriptManager</span>
    <span style="color: #008000">// in AJAX Control Toolkit</span>
    <span style="color: #0000ff">private</span> Stream GetOutputStream() {
      Stream outputStream = Response.OutputStream;
      <span style="color: #0000ff">if</span>(!Request.Browser.IsBrowser(<span style="color: #006080">&quot;IE&quot;</span>) ||
                         (6 &lt; Request.Browser.MajorVersion)) {
        <span style="color: #0000ff">foreach</span>(
          <span style="color: #0000ff">string</span> acceptEncoding <span style="color: #0000ff">in</span> (Request.Headers[<span style="color: #006080">&quot;Accept-Encoding&quot;</span>] ??
                                       <span style="color: #006080">&quot;&quot;</span>).ToUpperInvariant().Split(<span style="color: #006080">','</span>)) {
          <span style="color: #0000ff">if</span>(<span style="color: #006080">&quot;GZIP&quot;</span> == acceptEncoding) {
            Response.AddHeader(<span style="color: #006080">&quot;Content-encoding&quot;</span>, <span style="color: #006080">&quot;gzip&quot;</span>);
            outputStream = <span style="color: #0000ff">new</span> GZipStream(outputStream,
                                          CompressionMode.Compress);
            <span style="color: #0000ff">break</span>;
          }
          <span style="color: #0000ff">if</span>(<span style="color: #006080">&quot;DEFLATE&quot;</span> == acceptEncoding) {
            Response.AddHeader(<span style="color: #006080">&quot;Content-encoding&quot;</span>, <span style="color: #006080">&quot;deflate&quot;</span>);
            outputStream = <span style="color: #0000ff">new</span> DeflateStream(outputStream,
                                             CompressionMode.Compress);
            <span style="color: #0000ff">break</span>;
          }
        }
      }
      <span style="color: #0000ff">return</span> outputStream;
    }
  }
}</pre>
</div>
<p>The ASCX is empty:</p>
<div style="padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 1000px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; height: 42px; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;%@ Control Language=<span style="color: #006080">&quot;C#&quot;</span> AutoEventWireup=<span style="color: #006080">&quot;true&quot;</span> CodeBehind=<span style="color: #006080">&quot;Get.ascx.cs&quot;</span> Inherits=<span style="color: #006080">&quot;TestDependencies.Views.ControlDependencies.Get&quot;</span>  %&gt;</pre>
</div>
<p>There are two advantages to using this technique.&#160; Firstly performance should be increased since all the required scripts are returned in a single response.&#160; Secondly you don't have to manually work out the dependencies for a particular ASP.NET AJAX Control Toolkit control.</p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2008/10/22/mvc-control-toolkit-dependencies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ASP.NET MVC and the AJAX Control Toolkit</title>
		<link>http://damianblog.com/2008/09/07/using-aspnet-mvc-and-the-ajax-control-toolkit/</link>
		<comments>http://damianblog.com/2008/09/07/using-aspnet-mvc-and-the-ajax-control-toolkit/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 12:27:43 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://damianblog.com/2008/09/07/using-aspnet-mvc-and-the-ajax-control-toolkit/</guid>
		<description><![CDATA[There are a whole range of useful AJAX behaviors available in the ASP.NET AJAX Control Toolkit, and it would be cool to be able to use them from ASP.NET MVC.&#160; In this post I'll show you how you can use one of the extenders that I created, the ListSearch Extender, with ASP.NET MVC. Set up [...]]]></description>
			<content:encoded><![CDATA[<p>There are a whole range of useful AJAX behaviors available in the ASP.NET AJAX Control Toolkit, and it would be cool to be able to use them from ASP.NET MVC.&#160; </p>
<p>In this post I'll show you how you can use one of the extenders that I created, the <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ListSearch/ListSearch.aspx">ListSearch Extender</a>, with ASP.NET MVC.</p>
<h2>Set up your ASP.NET MVC Project</h2>
<p>To start create a new ASP.NET MVC project.</p>
<p>Next download the <a href="http://www.asp.net/ajax/downloads/library/">Microsoft AJAX Library</a>, which contains the Javascript library used in the Microsoft ASP.NET AJAX implementation. Copy the <em>MicrosoftAjaxLibrary</em> folder in the ZIP you downloaded to the <em>Content</em> folder in your MVC project.</p>
<p>Now download the <strong>Script Only Files</strong> from the <a href="http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx">ASP.NET AJAX Control Toolkit</a> and copy the <em>AjaxControlToolkit</em> folder in the ZIP to the <em>Content</em> f0lder in your MVC project.</p>
<p>Now that the folders are copied you need to make them visible to the project.&#160; Open the <em>Content</em> branch of your project in the Solution Explorer, and then click on the <em>Show All Files</em> button:</p>
<p><a href="http://www.atadore.com/images/Usi.NETMVCandAJAXControlToolkitListSearc_B2B2/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="194" alt="" src="http://www.atadore.com/images/Usi.NETMVCandAJAXControlToolkitListSearc_B2B2/image_thumb.png" width="244" align="left" border="0" /></a> <a href="http://www.atadore.com/images/Usi.NETMVCandAJAXControlToolkitListSearc_B2B2/image_3.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="168" alt="" src="http://www.atadore.com/images/Usi.NETMVCandAJAXControlToolkitListSearc_B2B2/image_thumb_3.png" width="244" border="0" /></a> </p>
<p>&#160;</p>
<p>Once you do this, you should see the two folders that you copied into the <em>Content</em> folder.&#160; Right click on each folder and select <em>Include In Project</em>.</p>
<p>Now your MVC project will have access to the JavaScript files it requires.</p>
<h2>Add the SELECT</h2>
<p>To make use of these JavaScript libraries, open the Home action's Index view under <em>Views-&gt;Home-&gt;Index.aspx</em>.&#160; Modify the HTML to include a simple SELECT List:</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;%@ Page Language=<span style="color: #006080">&quot;C#&quot;</span> ... %&gt;

&lt;asp:Content ID=<span style="color: #006080">&quot;indexContent&quot;</span> ContentPlaceHolderID=<span style="color: #006080">&quot;MainContent&quot;</span> runat=<span style="color: #006080">&quot;server&quot;</span>&gt;
    &lt;h2&gt; &lt;%= Html.Encode(ViewData[<span style="color: #006080">&quot;Message&quot;</span>]) %&gt;&lt;/h2&gt;
    &lt;p&gt;
        To learn more about ASP.NET MVC visit ...
    &lt;/p&gt;

    &lt;select id=<span style="color: #006080">&quot;Countries&quot;</span>&gt;
    &lt;option&gt;Switzerland&lt;/option&gt;
    &lt;option&gt;United Kindom&lt;/option&gt;
    &lt;option&gt;United States&lt;/option&gt;
    &lt;/select&gt;

&lt;/asp:Content&gt;</pre>
</div>
<div>&#160;</div>
<h2>Include the required Javascript files</h2>
<p>Next you'll need to have the page pull in the JavaScript files that are used by the ListSearch Extender:</p>
<div>
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&lt;script type=<span style="color: #006080">&quot;text/javascript&quot;</span> src=<span style="color: #006080">&quot;/Content/MicrosoftAjaxLibrary/System.Web.Extensions/3.5.0.0/3.5.21022.8/MicrosoftAjax.debug.js&quot;</span>/&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.Common.Common.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.ExtenderBase.BaseScripts.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.DynamicPopulate.DynamicPopulateBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.Compat.Timer.Timer.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.Animation.Animations.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.Animation.AnimationBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.PopupExtender.PopupBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.PopupControl.PopupControlBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;script src=<span style="color: #006080">&quot;/Content/AjaxControlToolkit/3.0.20820.16598/3.0.20820.0/AjaxControlToolkit.ListSearch.ListSearchBehavior.js&quot;</span> type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;</pre>
</p></div>
</div>
<div>&#160;</div>
<div>You may need to change the version numbers depending on the versions of the Microsoft AJAX library and Toolkits you downloaded.</div>
<div>&#160;</div>
<div>I found out which script files to include by creating a normal ASP.NET Project that used the ListSearch Extender, and set the ScriptManager's ScriptPath property to a new folder I created in the project called <em>/MicrosoftAjaxLibrary</em>, to which I copied the same two folders that I copied to the <em>Content</em> folder above.&#160; I accessed the page, and did a View Source to see what JavaScript was being used.</div>
<div>&#160;</div>
<h2>Initialize the Extender</h2>
<p>Having included the required JavaScript files, you can now create a new ListSearch Extender and attach it to the SELECT you created above:</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;script type=<span style="color: #006080">&quot;text/javascript&quot;</span>&gt;
    Sys.Application.initialize();
    Sys.Application.add_init(<span style="color: #0000ff">function</span>() {
    $create(AjaxControlToolkit.ListSearchBehavior,
            { <span style="color: #006080">&quot;id&quot;</span>: <span style="color: #006080">&quot;ListBox1_ListSearchExtender&quot;</span> },
            <span style="color: #0000ff">null</span>, <span style="color: #0000ff">null</span>, $get(<span style="color: #006080">&quot;Countries&quot;</span>));
    });
&lt;/script&gt;</pre>
</div>
<div>&#160;</div>
<h2></h2>
<h2></h2>
<h2>Access your page</h2>
<div>&#160;</div>
<div>Now when you run you'll get the ListSearch Extender behavior attached to your SELECT:</div>
<div><a href="http://www.atadore.com/images/Usi.NETMVCandAJAXControlToolkitListSearc_B2B2/image_4.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="303" alt="" src="http://www.atadore.com/images/Usi.NETMVCandAJAXControlToolkitListSearc_B2B2/image_thumb_4.png" width="476" border="0" /></a></div>
<div>&#160;</div>
<h2>Summary </h2>
<div>&#160;</div>
<div>Using the AJAX Control Toolkit is very straight-forward.&#160; The trickiest part is determining exactly what script files you need to include.</div>
<div>&#160;</div>
<div>Now you can use the whole set of behaviors that other people have created to add AJAX goodness to your ASP.NET MVC projects.</div>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2008/09/07/using-aspnet-mvc-and-the-ajax-control-toolkit/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

