<?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>Chris van de Steeg &#187; javascript</title>
	<atom:link href="http://www.chrisvandesteeg.nl/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisvandesteeg.nl</link>
	<description>What&#039;s practical is logical</description>
	<lastBuildDate>Fri, 03 Feb 2012 06:58:48 +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>jQuery ajax with asp.net mvc preview 5</title>
		<link>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 18:48:57 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/?p=64</guid>
		<description><![CDATA[Quite some had changed between mvc p4 and mvc p5, so it took some time too update my jquery4mvc project to preview 5. Be sure to check out scott&#8217;s post to read all the new stuff. He&#8217;ll be posting on the ajaxhelpers some time soon also.&#160; If you wish to skip the reading and directly [...]]]></description>
			<content:encoded><![CDATA[<p>Quite some had changed between mvc p4 and mvc p5, so it took some time too update my jquery4mvc project to preview 5. Be sure to check out <a href="http://weblogs.asp.net/scottgu/archive/2008/09/02/asp-net-mvc-preview-5-and-form-posting-scenarios.aspx">scott&#8217;s post</a> to read all the new stuff. He&#8217;ll be posting on the ajaxhelpers some time soon also.&#160; If you wish to skip the reading and directly download the stuff: it&#8217;s at <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=17401">codeplex</a>. </p>
<p>The javascript-only package includes 3 javascript files that allow you to use the default Microsoft AjaxHelper. You can just copy those files to your Content folder and include them in your head section, instead of the MicrosoftAjax.js and MicrosoftMvcAjax.js. All ajax extensions work the same as their Microsoft equivalence,&#160; using jQuery instead of MicrosoftAjax. As a little bonus, you&#8217;ll get back and forward button support for your ajax-links.</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="92" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image-thumb.png" width="644" border="0" /></a> </p>
<p>That&#8217;s it, go ahead and use the AjaxHelper functions like you&#8217;re used to. Though a few things have changed for the AjaxHelpers in preview 5, you could still use the introduction <a href="http://www.hanselman.com/blog/ASPNETMVCPreview4UsingAjaxAndAjaxForm.aspx">ASP.NET MVC Preview 4 &#8211; Using Ajax and Ajax.Form</a> by Scott Hanselman if you haven&#8217;t already checked out the AjaxHelper. Main thing that has changed is that you cannot use inline javascript in the AjaxOptions in preview 5, you should now specify a method name. You could also download the entire jQueryMvc project, it holds a sample website showing some of the ajax magic.</p>
<p>Talking about the entire project, it&#8217;s more than just the .js files! The intention of the project is to get you up and running very quickly when you want to create an mvc based ajax application. We use <a href="http://codeplex.com/unity">Unity</a> as our default IoC container.</p>
<p>I think it&#8217;s quite hard to explain exactly what the project does for you, it&#8217;s best really to just look at the sample website, but I will give a brief overview. First, we have a DefaultViewViewEngine. If you mark your controller with a [DefaultView] attribute like so:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="55" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image1.png" width="406" border="0" /> </p>
<p>If you call in example /Home/Index, by default the Index view will be searched for. If it isn&#8217;t found, the DefaultViewViewEngine will look for a template with the name specified (&quot;default&quot; in the above example). It doesn&#8217;t matter what viewengine you use for your views, it will work for all of them. So what can this do? Look at the structure of the views in the sample site:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="261" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image2.png" width="189" border="0" /> </p>
<p>As you can see, most of the the views only have an ascx file prefixed with an underscore. Since the views are not found when the actions Home/About, Home/SayHello, Home/Index are called upon, the DefaultViewViewEngine will open Shared/Default.aspx.    <br />This default page does not do much<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="76" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image3.png" width="879" border="0" /> </p>
<p>As you can see, it just uses the masterpage. But with only little imagination, you can see that you can easily create different default-pages for each controller. The masterpage however, does hold some extra magic:</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="55" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2008/09/image4.png" width="506" border="0" /></p>
<p>This special contentplaceholder, by default works like a normal placeholder. But, if it doesn&#8217;t get new content from it&#8217;s page, it will ask the ViewEngine(s) to open the view of the current action prefixed with an underscore. So, if you call Home/About, this will ask for Home/_About.&#160; <br />Can you see the magic? For all similar pages, you just have to create the ascx files (or other partials if you use a different viewengine). Those partial views will be pushed into the main page.</p>
<p>But wait, there&#8217;s more! If you make an ajax-request to a controller that has the [AjaxController] attribute, it will return only the partial view! Now, isn&#8217;t that great ? That looks a lot like the updatepanel to me <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=17401">Go to codeplex and download the project to see the ajax-magic I&#8217;m so excited about!</a>    <br />Source can be downloaded at Google code: <a href="http://code.google.com/p/jquerymvc/source/checkout">http://code.google.com/p/jquerymvc/source/checkout</a>    <br />The sample website can be seen in action at: <a title="http://www.chrisvandesteeg.nl/demo/jquerymvc5/" href="http://www.chrisvandesteeg.nl/demo/jquerymvc5/">http://www.chrisvandesteeg.nl/demo/jquerymvc5/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/09/16/jquery-ajax-with-aspnet-mvc-preview-5/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Howto use jQuery with asp.net mvc preview 4&#8242;s AjaxHelper</title>
		<link>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/</link>
		<comments>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 20:56:11 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/</guid>
		<description><![CDATA[Working on jQuery4mvc preview 4, one of the first things I ofcourse wanted to do was to replace the ASP.NET Ajax library that&#8217;s used by the AjaxHelper. Unfortunately the AjaxHelper itself is sealed, so atm we can&#8217;t (easily) change how the AjaxHelper generates its links. So, as an alternative, I created a javascript library that [...]]]></description>
			<content:encoded><![CDATA[<p>Working on jQuery4mvc preview 4, one of the first things I ofcourse wanted to do was to replace the ASP.NET Ajax library that&#8217;s used by the AjaxHelper.</p>
<p>Unfortunately the AjaxHelper itself is sealed, so atm we can&#8217;t (easily) change how the AjaxHelper generates its links. So, as an alternative, I created a javascript library that uses the same methodnames as the MicrosoftMvcAjax version.</p>
<p>Though at first I was upset that AjaxHelper wasn&#8217;t opened up, this javascript-only solution makes it very easy to use. All you have to do is </p>
<ul>
<li>place the <a href="http://jquery.com/">latest jQuery version</a> in your Content folder; </li>
<li>place <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=15521">my javascript file</a> in your Content folder; </li>
<li>add references in your views (or masterpage ofcourse) to these 2 files instead of referencing the MicrosoftMvcAjax.js and MicrosoftAjax.js file.</li>
</ul>
<p>If you haven&#8217;t played with the AjaxHelper yet, take a look at <a href="http://www.hanselman.com/blog/ASPNETMVCPreview4UsingAjaxAndAjaxForm.aspx">Scott Hanselman&#8217;s post on Using Ajax and Ajax.Form</a></p>
<p>This jQuery version also has a little extra: browser-history support for your ajax requests</p>
<p>Now, go <a href="http://www.codeplex.com/jquery4mvc/Release/ProjectReleases.aspx?ReleaseId=15521">download</a> the js file and play!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2008/07/21/howto-use-jquery-with-aspnet-mvc-preview-4s-ajaxhelper/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Ajax and json for ASP.NET MVC with jQuery</title>
		<link>http://www.chrisvandesteeg.nl/2007/12/19/ajax-and-json-for-aspnet-mvc-with-jquery/</link>
		<comments>http://www.chrisvandesteeg.nl/2007/12/19/ajax-and-json-for-aspnet-mvc-with-jquery/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 17:28:39 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.chrisvandesteeg.nl/2007/12/19/ajax-and-json-for-aspnet-mvc-with-jquery/</guid>
		<description><![CDATA[I&#8217;ve created an example project that uses the jQuery library to create an ajax enabled ASP.NET MVC website. Generally what this project does: Load views through ajax (with back-button support) Do ajax-style form-posts and retrieve only the messages, errors and updated content Do json form-posts and retrieve the errors and messages as a json object [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created an example project that uses the <a href="http://jquery.com">jQuery</a> library to create an ajax enabled <a href="http://weblogs.asp.net/scottgu/archive/2007/12/09/asp-net-3-5-extensions-ctp-preview-released.aspx">ASP.NET MVC</a> website. Generally what this project does:</p>
<ul>
<li>Load views through ajax (with back-button support) </li>
<li>Do ajax-style form-posts and retrieve only the messages, errors and updated content </li>
<li>Do json form-posts and retrieve the errors and messages as a json object </li>
</ul>
<p>Here are the quicklinks for all you people who don&#8217;t want to read the story.</p>
<ul>
<li><a href="/demo/jquerymvc/">View online demo</a> </li>
<li><a href="/download/jquerymvc/jquerymvc.zip">Download webproject</a> </li>
<li><a href="/download/jquerymvc/jquerymvc.vsi">Download Visual Studio template</a> </li>
</ul>
<p>For all you people who want read about it before playing around, here&#8217;s a little intro to the code&#8230;</p>
<p>The project contains a BaseController, which should be inherited by all your controllers. This controller (ofcourse) overrides the System.Web.Mvc.Controller and handles the detection of Ajax requests and/or Json requests. It does that by overriding the Execute method and reading some http-headers. Unfortunately reading http-headers is the only (evil) way I know to detect this.    <br />Fortunately, while I was playing with this project, I saw that <a href="http://weblogs.asp.net/mschwarz/archive/2007/12/19/mvc-web-application-and-json.aspx">Michael Schwarz</a> posted exactly (well, 99%) the same solution as I figured out, so for now I&#8217;ll take this as the best solution until someone provides me a better one.</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image3.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="748" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image-thumb2.png" width="536" border="0" /></a></p>
<p>As you can see, there&#8217;s also some error handling in here. If there is an exception thrown during the controller execution, it&#8217;s wrapped in a simple class called SimpleException. This class is easily serializable, so it can be passed on as a javascript object to the browser, in case of a json request.&#160; In case of a non-json request (either normal or ajax), the default error handler called &quot;error.aspx&quot; in views/shared/ is rendered.</p>
<p>The BaseController also overrides the RenderView. In the RenderView, we do some special stuff if the request is a json- or ajax-request.</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image4.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="536" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image-thumb3.png" width="537" border="0" /></a></p>
<p>If the current request is a json-request, the template &quot;json.aspx&quot; is called upon. The default &quot;json.aspx&quot; is located at /views/shared/json.aspx and the only thing it does is serializing the current ViewData.</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image5.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="110" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image-thumb4.png" width="434" border="0" /></a></p>
<p>One special note is that in the codebehind, I had &#8216;strong type&#8217; the ViewData to an &#8216;object&#8217;, since the ViewData class doesn&#8217;t allow us to serialize the real object.</p>
<p>Then there are the 2 masterpages: ajax.master and site.master. Both of them contain 4 ContentPlaceHolders:</p>
<ul>
<li>Errors </li>
<li>Messages </li>
<li>maincontent </li>
<li>dynamiccontent </li>
</ul>
<p>Errors and messages should ofcourse output the errors and informational messages for the current request. I created a handy extension method on the HtmlHelper to quickly output these:</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image6.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="171" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image-thumb5.png" width="494" border="0" /></a></p>
<p>The maincontent should contain the entire page without the usual MasterPage stuff (eg navigation). The dynamiccontent should only contain the content that can change during the same request (eg. the &#8216;hello {name}&#8217; part in the <a href="/demo/jquerymvc/">demo</a>).</p>
<p>In case of an ajax request, the javascript adds a querystring to the request telling what content is requested (either maincontent or dynamiccontent) and the ajax.master decides what to output for that request based on this querystring:</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image7.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="314" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image-thumb6.png" width="536" border="0" /></a></p>
<p>Ajax links are very easily created, also through an extension method:</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image8.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="58" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image-thumb7.png" width="536" border="0" /></a></p>
<p>The first parameter is the text of the link, the second one is the action on the controller and the third one is the id of the container-div.</p>
<p>The other client functions are all form related, you an see them in use in the /views/home/index.aspx template:</p>
<p><a href="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image9.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="203" alt="image" src="http://www.chrisvandesteeg.nl/wp-content/uploads/2007/12/image-thumb8.png" width="534" border="0" /></a></p>
<p>You can use any of these methods to submit your forms, just use them as you like it. The methods can be found in /Content/mvc.js</p>
<p>Well that should be enough talking about code, just go ahead and play to find out the rest by yourself.</p>
<li><a href="/demo/jquerymvc/">View online demo</a> </li>
<li><a href="/download/jquerymvc/jquerymvc.zip">Download webproject</a> </li>
<li><a href="/download/jquerymvc/jquerymvc.vsi">Download Visual Studio template</a> </li>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2007/12/19/ajax-and-json-for-aspnet-mvc-with-jquery/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Flash, hashes and ms ie bug</title>
		<link>http://www.chrisvandesteeg.nl/2006/09/15/flash-hashes-and-ms-ie-bug/</link>
		<comments>http://www.chrisvandesteeg.nl/2006/09/15/flash-hashes-and-ms-ie-bug/#comments</comments>
		<pubDate>Fri, 15 Sep 2006 11:19:44 +0000</pubDate>
		<dc:creator>Chris van de Steeg</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.ilikeu2.nl/2006/09/15/flash-hashes-and-ms-ie-bug/</guid>
		<description><![CDATA[So today I was going to enable backbutton &#038; bookmarking support for our epaper viewer (http://epaperdemos.modernmedia.nl/ &#8211; Dutch). To make this happen I ofcourse use the hash in the location, i.e. #2 for page 2. But weird things seem to happen with hashes &#038; flash on the same page. It isn&#8217;t my own flash file [...]]]></description>
			<content:encoded><![CDATA[<p>So today I was going to enable backbutton &#038; bookmarking support for our epaper viewer (<a target="_blank" title="ModernMedia clixmaster republisher demos" href="http://epaperdemos.modernmedia.nl/">http://epaperdemos.modernmedia.nl/</a> &#8211; Dutch). To make this happen I ofcourse use the hash in the location, i.e. #2 for page 2. But weird things seem to happen with hashes &#038; flash on the same page. It isn&#8217;t my own flash file that does this, it also happens on adobe.com for example.</p>
<p>Go to <a target="_blank" href="http://www.adobe.com/#logicalley">http://www.adobe.com/#logicalley</a> using internet explorer and notice how #logicalley gets added to internet explorer&#8217;s window title as soon as the flash file is loaded &#8230; How weird is that.</p>
<p>I suspect that adobe&#8217;s flash is the one who causes this bug, since it does not seem to happen with other &lt;object /&gt; tags.</p>
<p>And more strange stuff seems to happen with the title. To reproduce:</p>
<ul>
<li>Type <em>_is_</em> behind #logicalley in the url</li>
<li>Hit enter</li>
<li>Type <em>logical</em> behind #logicalley_is_ in the url</li>
<li>Hit enter</li>
</ul>
<p>The whole document title has dissapeared <img src='http://www.chrisvandesteeg.nl/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisvandesteeg.nl/2006/09/15/flash-hashes-and-ms-ie-bug/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

