<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Ajax</title>
        <link>http://www.ayende.com/Blog/category/497.aspx</link>
        <description>Ajax</description>
        <language>en-US</language>
        <copyright>Ayende Rahien</copyright>
        <managingEditor>Ayende@ayende.com</managingEditor>
        <generator>Subtext Version 1.9.3.51</generator>
        <item>
            <title>ASP.Net Ajax, Error Handling and WTF</title>
            <link>http://ayende.com/Blog/archive/2008/01/06/ASP.Net-Ajax-Error-Handling-and-WTF.aspx</link>
            <description>&lt;br /&gt;
I am facing some really unpleasant choices at the moment. And I thought it would be so easy.&lt;br /&gt;
I wanted to add global error handling to all the web services that we expose as [ScriptService].&lt;br /&gt;
For some reason, they didn't show up in the Application_Error event, and that caused the exception details to be sent to the client.&lt;br /&gt;
It looks like for some strange reasons, web services exceptions don't go through the Application_Error, so I implemented a SoapExtension to handle that, but ScriptService doesn't go through the Soap layers, so it obviously doesn't work.&lt;br /&gt;
Then I went and looked at the code.&lt;br /&gt;
The whole thing is _hard coded_ inside, and there is no way in.&lt;br /&gt;
No way to globally capture exception being raised from script services.&lt;br /&gt;
No way in to add this ability.&lt;br /&gt;
Urgh! Argh!&lt;br /&gt;
&lt;br /&gt;
I mean, it is not like I want something very special, it sounds to me like a reasonable request.&lt;br /&gt;
Yes, I know you can turn off the error in the config, but I would like, you know, to log this. &lt;br /&gt;
&lt;br /&gt;
Of course, everything is internal in there, so I can't just go and override the RestHandler. ExecuteWebServiceCall(), I would have to have a private build of this stuff.&lt;br /&gt;
Just to be able to log exceptions.&lt;img src="http://ayende.com/Blog/aggbug/9989.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/01/06/ASP.Net-Ajax-Error-Handling-and-WTF.aspx</guid>
            <pubDate>Sun, 06 Jan 2008 14:47:19 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2008/01/06/ASP.Net-Ajax-Error-Handling-and-WTF.aspx#feedback</comments>
            <slash:comments>11</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9989.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Javascript, lexical scopes and what your momma thought you about variables</title>
            <link>http://ayende.com/Blog/archive/2007/12/13/Javascript-lexical-scopes-and-what-your-momma-thought-you-about.aspx</link>
            <description>&lt;p&gt;Let us assume that we have this amazing javascript function:&lt;/p&gt; &lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt; test()
{
	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; nums = [1,2,3,4,5,6,7];
	&lt;span style="color: #0000ff"&gt;for&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; i = 0; i&amp;lt;nums.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt;; i++)
	{
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; alertLink = &lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.createElement("&lt;span style="color: #8b0000"&gt;A&lt;/span&gt;");
		alertLink.href = "&lt;span style="color: #8b0000"&gt;#&lt;/span&gt;";
		alertLink.innerHTML = nums[i];
		
		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;( nums[i] % 2 == 0)
		{
			alertLink.onclick = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('EVEN: '+ nums[i]); };
		}
		&lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
		{
			alertLink.onclick = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('ODD: ' + nums[i]); };
		}
		
		&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.firstChild.appendChild(alertLink);
		&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.firstChild.appendChild(&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.createElement("&lt;span style="color: #8b0000"&gt;BR&lt;/span&gt;"));
		
	}
}&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;Can you guess what it would generate? Quite a few undefines alerts, as a matter of fact. Why is that? Because the anonymous function is a closure, which capture not the value of i, but the i variable itself.&lt;/p&gt;
&lt;p&gt;This means when we click on a link that this method has generated, we use the last known value of i. Since we have exited the loop, i is actually 8.&lt;/p&gt;
&lt;p&gt;Now, in C# we have the same problem, and we can solve it by introducing a temporary variable in the loop, so we change the code to look like this:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;	
&lt;span style="color: #0000ff"&gt;function&lt;/span&gt; test()
{
	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; nums = [1,2,3,4,5,6,7];
	&lt;span style="color: #0000ff"&gt;for&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; i = 0; i&amp;lt;nums.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt;; i++)
	{
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; alertLink = &lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.createElement("&lt;span style="color: #8b0000"&gt;A&lt;/span&gt;");
		alertLink.href = "&lt;span style="color: #8b0000"&gt;#&lt;/span&gt;";
		alertLink.innerHTML = nums[i];
		
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; tmpNum = nums[i];
		
		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;( nums[i] % 2 == 0)
		{
			alertLink.onclick = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('EVEN: '+ tmpNum ); };
		}
		&lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
		{
			alertLink.onclick = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('ODD: ' + tmpNum ); };
		}
		
		&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.firstChild.appendChild(alertLink);
		&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.firstChild.appendChild(&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.createElement("&lt;span style="color: #8b0000"&gt;BR&lt;/span&gt;"));
		
	}
}&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;Try to run it, and you'll get an.. interesting phenomenon. All the links will show tmpNum as 7. Again, we captured the variable itself, not its value. And in JS, it looks like you are getting the same variable in the loop, not a new one (this is absolutely the wrong way to describe it, but it is a good lie), like you would in C#.&lt;/p&gt;
&lt;p&gt;What is even more interesting is that you would get the exact same result here:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;	
&lt;span style="color: #0000ff"&gt;function&lt;/span&gt; test()
{
	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; nums = [1,2,3,4,5,6,7];
	&lt;span style="color: #0000ff"&gt;for&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; i = 0; i&amp;lt;nums.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt;; i++)
	{
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; alertLink = &lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.createElement("&lt;span style="color: #8b0000"&gt;A&lt;/span&gt;");
		alertLink.href = "&lt;span style="color: #8b0000"&gt;#&lt;/span&gt;";
		alertLink.innerHTML = nums[i];
		
		
		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;( nums[i] % 2 == 0)
		{
			&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; tmpNum = nums[i];
			alertLink.onclick = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('EVEN: '+ tmpNum ); };
		}
		&lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
		{
			&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; tmpNum = nums[i];
			alertLink.onclick = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('ODD: ' + tmpNum ); };
		}
		
		&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.firstChild.appendChild(alertLink);
		&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.firstChild.appendChild(&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.createElement("&lt;span style="color: #8b0000"&gt;BR&lt;/span&gt;"));
		
	}
}&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;Here we have two different lexical scopes, with respectively different variables. Looks like it should work. But the lexical scope of JS is the function, not the nearest set of curly. Both tmpNum refer to the same variable, and as such, are keeping the last value in it.&lt;/p&gt;
&lt;p&gt;If the lexical scope is a function, we need to use a function then. Here is a version that works:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;	
&lt;span style="color: #0000ff"&gt;function&lt;/span&gt; test()
{
	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; nums = [1,2,3,4,5,6,7];
	&lt;span style="color: #0000ff"&gt;for&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; i = 0; i&amp;lt;nums.&lt;span style="color: #0000ff"&gt;length&lt;/span&gt;; i++)
	{
		&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; alertLink = &lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.createElement("&lt;span style="color: #8b0000"&gt;A&lt;/span&gt;");
		alertLink.href = "&lt;span style="color: #8b0000"&gt;#&lt;/span&gt;";
		alertLink.innerHTML = nums[i];
		
	
		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;( nums[i] % 2 == 0)
		{
			&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; act = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;(tmpEVEN)
			{
				alertLink.onclick = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('EVEN: '+tmpEVEN); };
			};
			act(nums[i]);
		}
		&lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
		{
			&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; tmpODD = nums[i];
			alertLink.onclick = &lt;span style="color: #0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color: #0000ff"&gt;alert&lt;/span&gt;('ODD: ' + tmpODD); };
		}
		
		&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.firstChild.appendChild(alertLink);
		&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.firstChild.appendChild(&lt;span style="color: #0000ff"&gt;document&lt;/span&gt;.createElement("&lt;span style="color: #8b0000"&gt;BR&lt;/span&gt;"));
		
	}
}&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;And that is it for today's JS lesson. &lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/9947.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/12/13/Javascript-lexical-scopes-and-what-your-momma-thought-you-about.aspx</guid>
            <pubDate>Wed, 12 Dec 2007 23:24:13 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/12/13/Javascript-lexical-scopes-and-what-your-momma-thought-you-about.aspx#feedback</comments>
            <slash:comments>8</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9947.aspx</wfw:commentRss>
        </item>
        <item>
            <title>You leave a team alone for one week...</title>
            <link>http://ayende.com/Blog/archive/2007/12/03/You-leave-a-team-alone-for-one-week.aspx</link>
            <description>&lt;p&gt;And they go ahead and write Outlook Web Access behind your back...&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Youleaveateamaloneforoneweek_C2CF/image.png" atomicselection="true"&gt;&lt;img height="231" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/Youleaveateamaloneforoneweek_C2CF/image_thumb.png" width="336" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;I am going over the code, and I am simply amazed. JavaScript &amp;amp; HTML component, using &lt;a href="http://www.ayende.com/Blog/archive/2007/11/23/A-different-UI-approach.aspx"&gt;DomainJSon Generation&lt;/a&gt; and some additional smarts around that idea.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/9907.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/12/03/You-leave-a-team-alone-for-one-week.aspx</guid>
            <pubDate>Mon, 03 Dec 2007 11:54:14 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/12/03/You-leave-a-team-alone-for-one-week.aspx#feedback</comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9907.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Cross Site Scripting</title>
            <link>http://ayende.com/Blog/archive/2007/10/24/Cross-Site-Scripting.aspx</link>
            <description>&lt;p&gt;So I had to do it today, I had two pages, in two unrelated domains (foo.com and bar.com) and I had to open a page from one and interact with it. Security constraints disallow this, unfortantely. There are all sorts of ways around it, mostly focusing on proxies, but I didn't want to get into that for a simple page, so I decided to write my own stupid method to do it.&lt;/p&gt; &lt;p&gt;From foo.com, the calling page:&lt;/p&gt; &lt;blockquote&gt;&lt;pre&gt;var url = "&lt;span style="color: #8b0000"&gt;http://www.bar.com/someImportantPage.castle?id=15&lt;/span&gt;"&amp;amp;onCloseRedirectTo="&lt;span style="color: #8b0000"&gt; + &lt;/span&gt;
		encodeURIComponent(window.location.href + &lt;br /&gt;                          "&lt;span style="color: #8b0000"&gt;&amp;amp;returnUrl=&lt;/span&gt;"+ encodeURIComponent(window.location.href) );
window.open(url);&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;And using JS injection for the called page (I have some limited control there), I put:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(window.opener)
{
	var oldClose = window.close;
	window.close = function()
	{
		&lt;span style="color: #0000ff"&gt;if&lt;/span&gt;(window.opener &amp;amp;&amp;amp; window.returnValue )
		{
			var url = decodeURIComponent($.getURLParam('onCloseRedirectTo')) + 
							"&lt;span style="color: #8b0000"&gt;&amp;amp;idToAdd=&lt;/span&gt;" + window.returnValue;
			window.opener.location.href = url;
		}
		oldClose();
	};
}&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;And voila, it works. I'll leave the &lt;em&gt;how&lt;/em&gt; as an excersize for the reader. Suffice to say that if you want to add a local iframe to the mix you can even get it to work in an "ajaxian" fashion.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/9801.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/10/24/Cross-Site-Scripting.aspx</guid>
            <pubDate>Wed, 24 Oct 2007 19:07:28 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/10/24/Cross-Site-Scripting.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9801.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Handling javascript localization in Mono Rail</title>
            <link>http://ayende.com/Blog/archive/2007/10/07/Handling-javascript-localization-in-Mono-Rail.aspx</link>
            <description>&lt;p&gt;I run into the issue of having to alert the user of some error, and it brought home the fact that English &amp;amp; Hebrew are not easy to mix. In fact, code such as this is consider a very bad sign, usually code that you don't really want to touch, see or believe in:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/HandlingjavascriptlocalizationinMonoRail_F0EF/image.png" atomicselection="true"&gt;&lt;img height="35" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/HandlingjavascriptlocalizationinMonoRail_F0EF/image_thumb.png" width="286" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;So, we need some sort of a way to externalize those strings, even if the only language that this application is going to use is Hebrew, simply because of the pain of mixing the two together.&lt;/p&gt; &lt;p&gt;After thinking about it for a while, I decided to create this view (JavascriptResources/index.brail):&lt;/p&gt; &lt;blockquote&gt;&lt;pre&gt;&amp;lt;%
&lt;span style="color: #0000ff"&gt;for&lt;/span&gt; de &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; controller.Resources:
	resourceName = de.Key
%&amp;gt;
	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; ${resourceName} = {
	&amp;lt;% &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; item &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; GetParameter(resourceName): %&amp;gt;
		${item.Key}: '${item.Value.Replace("&lt;span style="color: #8b0000"&gt;'&lt;/span&gt;","&lt;span style="color: #8b0000"&gt;\\'&lt;/span&gt;") }',
	&amp;lt;% &lt;span style="color: #0000ff"&gt;end&lt;/span&gt; %&amp;gt;
		Empty: ''
	};
&amp;lt;%
&lt;span style="color: #0000ff"&gt;end&lt;/span&gt;
%&amp;gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;And here is the definition of the controller:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;[Resource("&lt;span style="color: #8b0000"&gt;Processes&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;MyApp.Resources.Javascript.Processes&lt;/span&gt;")]
[Resource("&lt;span style="color: #8b0000"&gt;Errors&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;MyApp.Resources.Javascript.Errors&lt;/span&gt;")]
[Resource("&lt;span style="color: #8b0000"&gt;Messages&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;MyApp.Resources.Javascript.Messages&lt;/span&gt;")]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; JavascriptResourcesController : Controller
{
	&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Index()
	{
		
	}
}
&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;But what the hell does this &lt;em&gt;do, &lt;/em&gt;anyway? Not much, actually, but it will iterate over all the registered resources for the controller, and output something that looks like this for each of those resources:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; Processes = {
 	EmploymentType: 'Employment Type',
	Details: 'Details',
	Dates: 'The dates',
	Empty: ''
};&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;The nice thing is that I can now write: alert(Errors.RecursiveError);*. As a side affect (as I said, the application is just in Hebrew so I don't care about that much), I also get the usual benefits of localization.&lt;/p&gt;
&lt;p&gt;* You have to read Hebrew to get the joke, I am afraid.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/9748.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/10/07/Handling-javascript-localization-in-Mono-Rail.aspx</guid>
            <pubDate>Sun, 07 Oct 2007 16:10:39 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/10/07/Handling-javascript-localization-in-Mono-Rail.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9748.aspx</wfw:commentRss>
        </item>
        <item>
            <title>YSlow: Another Web Developer adding for FireFox</title>
            <link>http://ayende.com/Blog/archive/2007/07/27/YSlow-Another-Web-Developer-adding-for-FireFox.aspx</link>
            <description>&lt;p&gt;After getting hooked into FireBug, it looks like &lt;a href="http://developer.yahoo.com/yslow/"&gt;YSlow&lt;/a&gt; it going to be another essential tool. Just the screen shots makes me want to drool...&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/9566.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/07/27/YSlow-Another-Web-Developer-adding-for-FireFox.aspx</guid>
            <pubDate>Fri, 27 Jul 2007 20:23:52 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/07/27/YSlow-Another-Web-Developer-adding-for-FireFox.aspx#feedback</comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9566.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using partials in Web Forms</title>
            <link>http://ayende.com/Blog/archive/2007/06/15/Using-partials-in-Web-Forms.aspx</link>
            <description>&lt;p&gt;Partial is a MonoRail term to a piece of UI that you extract outside, so you can call it again, often with Ajax. This is something that is harder to do in WebForms. Yesterday I found an elegant solution to the problem. &lt;/p&gt; &lt;p&gt;ASPX code:&lt;/p&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt; &lt;span style="color: #ff0000"&gt;id&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"UserDetailsDiv"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
   &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;ayende&lt;/span&gt;:&lt;span style="color: #800000"&gt;UserDetails&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runt&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"server"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"TheUserDetails"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;User Control:&lt;/p&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;
Name: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;asp&lt;/span&gt;:&lt;span style="color: #800000"&gt;label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Name"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"server"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;br&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;
Email: &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #c71585"&gt;asp&lt;/span&gt;:&lt;span style="color: #800000"&gt;label&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ID&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"Email"&lt;/span&gt; &lt;span style="color: #ff0000"&gt;runat&lt;/span&gt;=&lt;span style="color: #0000ff"&gt;"server"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;div&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Client Side Code:&lt;/p&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;function&lt;/span&gt; changeUser(newUserId, div)
{
	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; srv = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MyApp.Services.UserDetails();
	srv.GetUserDetailsView(newUserId, onSucccessGetUserDetailsView, &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;, div);
}

&lt;span style="color: #0000ff"&gt;function&lt;/span&gt; onSucccessGetUserDetailsView(response, userContext)
{
	&lt;span style="color: #0000ff"&gt;var&lt;/span&gt; div = $(userContext);
	div.innerHTML = response;
	&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Effect.Highlight(div);
}&lt;/pre&gt;
&lt;p&gt;Web Service Code:&lt;/p&gt;&lt;pre&gt;[WebMethod(EnableSession = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetUserDetailsView(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; userId)
{
	User user = Controller.GetUser(userId);
	&lt;span style="color: #008000"&gt;//there may be a better way to do this, I haven't bothered looking&lt;/span&gt;
	UserDetails userDetails = (UserDetails)&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Page().LoadControl("&lt;span style="color: #8b0000"&gt;~/Users/UserControls/UserDetails.ascx&lt;/span&gt;");
	userDetails.User = user;
	userDetails.DataBind();
	&lt;span style="color: #0000ff"&gt;using&lt;/span&gt;(StringWriter sw = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringWriter())
	&lt;span style="color: #0000ff"&gt;using&lt;/span&gt;(HtmlTextWriter ht = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; HtmlTextWriter(sw))
	{
		userDetails.RenderControl(ht);
		&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; sw.GetStringBuilder().ToSTring();
	}
}&lt;/pre&gt;&lt;img src="http://ayende.com/Blog/aggbug/9469.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/06/15/Using-partials-in-Web-Forms.aspx</guid>
            <pubDate>Fri, 15 Jun 2007 14:16:00 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/06/15/Using-partials-in-Web-Forms.aspx#feedback</comments>
            <slash:comments>11</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9469.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Bug hunting, looking around the box</title>
            <link>http://ayende.com/Blog/archive/2007/06/12/Bug-hunting-looking-around-the-box.aspx</link>
            <description>&lt;p&gt;    I just spent &lt;em&gt;way&lt;/em&gt; too long trying to figure out what is wrong with this code:&lt;/p&gt;&lt;div style="BORDER-RIGHT: #999999 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: #999999 1px solid; PADDING-LEFT: 4px; PADDING-BOTTOM: 4px; BORDER-LEFT: #999999 1px solid; WIDTH: 100%; PADDING-TOP: 4px; BORDER-BOTTOM: #999999 1px solid; BACKGROUND-COLOR: #ffffe1"&gt;    &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;        &lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;script&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt; &lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?&gt;="text4/javascript"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;        &lt;/span&gt;&lt;/span&gt;    &lt;/p&gt;    &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;        &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;        &lt;/span&gt;&lt;span style="COLOR: blue"&gt;function&lt;/span&gt; customerUpdated()&lt;o:p&gt;&lt;/o:p&gt;        &lt;/span&gt;    &lt;/p&gt;    &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;        &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;        &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;        &lt;/span&gt;    &lt;/p&gt;    &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;        &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;            &lt;/span&gt;//dostuff&lt;o:p&gt;&lt;/o:p&gt;        &lt;/span&gt;    &lt;/p&gt;    &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"&gt;        &lt;span style="FONT-SIZE: 10pt; LINE-HEIGHT: 115%; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;        &lt;/span&gt;}&lt;br /&gt;        &lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;script&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;br /&gt;        &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;DropDown&lt;/span&gt; &lt;span style="COLOR: red"&gt;ID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Customers"&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="server"&lt;/span&gt; &lt;span style="COLOR: red"&gt;DataTextField&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Name"&lt;/span&gt;&lt;span style="mso-tab-count: 1"&gt;   &lt;br /&gt;        &lt;/span&gt;&lt;span style="mso-tab-count: 1"&gt;       &lt;/span&gt;&lt;span style="COLOR: red"&gt;OnClientChanged&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="customerUpdated();"&lt;/span&gt; &lt;span style="COLOR: red"&gt;DataValueField&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Id"/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;        &lt;/span&gt;&lt;/span&gt;    &lt;/p&gt;&lt;/div&gt;&lt;p&gt;    The answer is below... but do try to figure it out&lt;/p&gt;&lt;p&gt;    .&lt;/p&gt;&lt;p&gt;    .&lt;/p&gt;&lt;p&gt;    .&lt;/p&gt;&lt;p&gt;    .&lt;/p&gt;&lt;p&gt;    .&lt;/p&gt;&lt;p&gt;    .&lt;/p&gt;&lt;p&gt;    .&lt;/p&gt;&lt;p&gt;    .&lt;/p&gt;&lt;p&gt;    Can you see the problem? Perhaps this will help:&lt;/p&gt;&lt;div style="BORDER-RIGHT: #999999 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: #999999 1px solid; PADDING-LEFT: 4px; PADDING-BOTTOM: 4px; BORDER-LEFT: #999999 1px solid; WIDTH: 100%; PADDING-TOP: 4px; BORDER-BOTTOM: #999999 1px solid; BACKGROUND-COLOR: #ffffe1"&gt;    &lt;p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;        &lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt;script&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Consolas; mso-bidi-font-family: 'Times New Roman'; mso-no-proof: yes"&gt; &lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="text&lt;strong&gt;&lt;font size="5"&gt;4&lt;/font&gt;&lt;/strong&gt;/javascript"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;        &lt;/span&gt;&lt;/span&gt;    &lt;/p&gt;&lt;/div&gt;&lt;p&gt;    Argh!!! I must have gone over it a hundred times and didn't see it.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/9453.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/06/12/Bug-hunting-looking-around-the-box.aspx</guid>
            <pubDate>Tue, 12 Jun 2007 14:31:35 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/06/12/Bug-hunting-looking-around-the-box.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9453.aspx</wfw:commentRss>
        </item>
        <item>
            <title>ASP.Net Ajax vs. Unit Tests</title>
            <link>http://ayende.com/Blog/archive/2007/05/06/ASP.Net-Ajax-vs.-Unit-Tests.aspx</link>
            <description>&lt;p&gt;    By definition, unit tests should be fast. Integration tests should be as fast as possible as well. Almost by definition, Javascript is not fast. In the battle between ASP.Net Ajax and my Unit/Integration tests, so far the only loser it me. This is the point when I am going to stop dedicating any more time to making this work. &lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/9268.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/05/06/ASP.Net-Ajax-vs.-Unit-Tests.aspx</guid>
            <pubDate>Sun, 06 May 2007 14:13:36 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/05/06/ASP.Net-Ajax-vs.-Unit-Tests.aspx#feedback</comments>
            <slash:comments>7</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9268.aspx</wfw:commentRss>
        </item>
        <item>
            <title>ASP.Net Ajax, Performance and Race Conditions, Oh MY!</title>
            <link>http://ayende.com/Blog/archive/2007/05/02/ASP.Net-Ajax-Performance-and-Race-Conditions-Oh-MY.aspx</link>
            <description>&lt;p&gt;    I have just tracked down the Nthbug in my application that I can blame ASP.Net Ajax for. To be rather exact, I can blame ASP.Net Ajax performance, and to be absolutely clear, I am talking about initialization performance. &lt;/p&gt;&lt;p&gt;    The main issue is that I keep running into is that it takes human noticable time for the extended behaviors to be set on the page. By human noticable time I means over a second. The immediate result is that users are able to interact with the page in unexpected ways. Leading to all sorts of reported bugs that are plain impossible to reproduce unless you are aware of it.&lt;/p&gt;&lt;p&gt;    Case in point, I have a link that point to a page, and on that link, I have defined the ModalPopupExtender. In the popup, the user is expected to fill some values, after which it will post to the next page. Imagine my surprise when I get a bug report saying that the next page showing an error about missing details. I tested it, the QA tested it, everything seemed to work, but the bug kept popping up every now and then.&lt;/p&gt;&lt;p&gt;    It took a while to understand that the key difference was how soon the link was pressed after the page was loaded. The QA saying "and now I am going to press this link" was usually just enough for ASP.Net Ajax to initialize itself correctly.&lt;/p&gt;&lt;p&gt;    The reasoning for this is that JavaScript is inheritly slow, and ASP.Net Ajax groups all the initialization code at the bottom of the page, so it is the last thing that is being run.  This is on a dual core, 3.4Ghz and 4Gb development machine! I am sick and tired of handling race conditions as it is, the last thing that I need is trying to handle them in &lt;em&gt;javascript&lt;/em&gt;!&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/9252.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2007/05/02/ASP.Net-Ajax-Performance-and-Race-Conditions-Oh-MY.aspx</guid>
            <pubDate>Wed, 02 May 2007 13:45:08 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2007/05/02/ASP.Net-Ajax-Performance-and-Race-Conditions-Oh-MY.aspx#feedback</comments>
            <slash:comments>9</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9252.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>