<?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>Andrey Shchekin &#187; JavaScript</title>
	<atom:link href="http://blog.ashmind.com/index.php/category/web/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ashmind.com</link>
	<description></description>
	<lastBuildDate>Mon, 15 Mar 2010 18:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Some thoughts on ASP.NET AJAX Roadmap</title>
		<link>http://blog.ashmind.com/2008/07/19/some-thoughts-on-aspnet-ajax-roadmap/</link>
		<comments>http://blog.ashmind.com/2008/07/19/some-thoughts-on-aspnet-ajax-roadmap/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 15:59:48 +0000</pubDate>
		<dc:creator>Andrey Shchekin</dc:creator>
				<category><![CDATA[ASP.NET AJAX]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.ashmind.com/index.php/2008/07/19/some-thoughts-on-aspnet-ajax-roadmap/</guid>
		<description><![CDATA[Coming from a vacation, I have just discovered a new ASP.NET AJAX roadmap. A post by Matt Berseth starts with a summary of discussion done so far. I have some personal opinions on the question of ASP.NET AJAX since our team worked with it a lot. So I decided to write a post instead of [...]]]></description>
			<content:encoded><![CDATA[<p>Coming from a vacation, I have just discovered a new <a href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14924">ASP.NET AJAX roadmap</a>. <a href="http://mattberseth.com/blog/2008/07/my_feedback_aspnet_ajax_roadma.html">A post</a> by <a href="http://mattberseth.com/">Matt Berseth</a> starts with a summary of discussion done so far.</p>
<p>I have some personal opinions on the question of ASP.NET AJAX since our team worked with it a lot. So I decided to write a post instead of just commenting existing discussion.</p>
<p>I think I have a slightly different approach to this framework, as compared to other posters. I do not have to choose jQuery/prototype/mootools over ASP.NET AJAX. It is obvious that chaining in jQuery makes life easier, and extending element whenever possible is also a friendly approach.</p>
<p>However, I will still use ASP.NET AJAX for the interoperability with ASP.NET architecture &#8212; I can have a JavaScript part for any control I have, and pass values between C# and JavaScript. Also the component lifecycle (being able to handle component references easily) is a large win for me.</p>
<p>What I do not like is the cumbersome get_/set_ requirement without a built-in shortcut (I <a href="http://blog.ashmind.com/index.php/2007/10/08/metaprogramming-in-javascript-auto-properties-for-aspnet-ajax/">described</a> one solution earlier) and cumbersome event subscription.</p>
<h4>Event Subscription</h4>
<p>So, let&#8217;s start with this roadmap sample:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>$query(<span class="str">"textarea.rich"</span>)</pre>
<pre><span class="lnum">   2:  </span>  .addHandler(<span class="str">"focus"</span>, <span class="kwrd">function</span>(e) {</pre>
<pre class="alt"><span class="lnum">   3:  </span>    Sys.Debug.trace(<span class="str">"focused into "</span> + (e.eventTarget.id || <span class="str">"?"</span>));</pre>
<pre><span class="lnum">   4:  </span>  })</pre>
<pre class="alt"><span class="lnum">   5:  </span>  .setStyle(<span class="str">"width"</span>, <span class="kwrd">function</span>() {</pre>
<pre><span class="lnum">   6:  </span>    <span class="kwrd">return</span> (document.body.clientWidth – 10) + <span class="str">"px"</span>;</pre>
<pre class="alt"><span class="lnum">   7:  </span>  })</pre>
<pre><span class="lnum">   8:  </span>  .create(Contoso.UI.RichTextBehavior, {</pre>
<pre class="alt"><span class="lnum">   9:  </span>    showToolbar: <span class="kwrd">true</span>,</pre>
<pre><span class="lnum">  10:  </span>    fonts: [<span class="str">"Arial"</span>, <span class="str">"Times"</span>, <span class="str">"Courier"</span>]</pre>
<pre class="alt"><span class="lnum">  11:  </span>  });</pre>
</div>
<p>What we have now in our project for event subscription is similar to this</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>with (Auto.Events) {</pre>
<pre><span class="lnum">   2:  </span>  when(textarea).gets(<span class="str">'focus'</span>).call(<span class="str">'textarea_got_focus'</span>).on(<span class="kwrd">this</span>);</pre>
<pre class="alt"><span class="lnum">   3:  </span>  when(list).has(<span class="str">'changed'</span>).call(<span class="kwrd">function</span>() { alert(<span class="str">'list_changed'</span>); })</pre>
<pre><span class="lnum">   4:  </span>}</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>
Which also alters dispose to remove the event handler (which is something very tedious to do manually).</p>
<p>So the thing I most dislike in new ASP.NET AJAX syntax is that it is not readable (just plain chaining). I see <a href="http://livepipe.net/extra/event_behavior">Event.Behavior</a> as a beautiful solution, jQuery&#8217;s as acceptable one (not a language, just more precise naming shortcuts), and ASP.NET AJAX as not really usable.</p>
<p>Same goes to $listen &#8212; I just can not remember the correct order of arguments unless looking directly to the documentation or IntelliSense. </p>
<p>But I think that $listen is a great idea, and the solution should be very interesting (considering that IE does not support <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mutationevents">DOM mutation events</a>).</p>
<h4>Templates</h4>
<p>Most popular post in my blog is about <a href="http://blog.ashmind.com/index.php/2007/06/21/client-side-databinding-with-aspnet-ajax-futures/">client-side databinding</a>. I can not show a solution that we have built to solve this issue (we have built it specifically for a project which sources I can not show), so this post is somewhat useless.</p>
<p>I am very hopeful about ASP.NET AJAX&#8217;s UI Templates, but I am also thinking about several problems we encountered.&nbsp; The first one is performance &#8212; it is absolutely necessary to pre-cache template binding function. The second one is binding repeated template with server controls.</p>
<p>There is a sample in the roadmap document:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="rem">&lt;!--* for (var i = 0; i &lt; features.length; i++) { *--&gt;</span></pre>
<pre><span class="lnum">   2:  </span>  <span class="kwrd">&lt;</span><span class="html">span</span><span class="kwrd">&gt;</span>{{ features[i].name }}<span class="kwrd">&lt;/</span><span class="html">span</span><span class="kwrd">&gt;</span></pre>
<pre class="alt"><span class="lnum">   3:  </span>  <span class="rem">&lt;!--* </span></pre>
<pre><span class="lnum">   4:  </span><span class="rem">    $create(Contoso.Tooltip, {</span></pre>
<pre class="alt"><span class="lnum">   5:  </span><span class="rem">      text: features[i].description</span></pre>
<pre><span class="lnum">   6:  </span><span class="rem">    }, {}, {}, $element);</span></pre>
<pre class="alt"><span class="lnum">   7:  </span><span class="rem">  *--&gt;</span></pre>
<pre><span class="lnum">   8:  </span><span class="rem">&lt;!--* } *--&gt;</span></pre>
</div>
<p>but I am not sure if it is possible to do this:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="rem">&lt;!--* for (var i = 0; i &lt; features.length; i++) { *--&gt;</span></pre>
<pre><span class="lnum">   2:  </span>  <span class="kwrd">&lt;</span><span class="html">my:Label</span> <span class="attr">Text</span><span class="kwrd">="{{ features[i].name }}"</span> <span class="kwrd">/&gt;</span></pre>
<pre class="alt"><span class="lnum">   3:  </span><span class="rem">&lt;!--* } *--&gt;</span></pre>
</div>
<p>where my:Label is a ASP.NET AJAX control. It was one the most complex problem for our client:Repeater, so I am interested if this would be implemented.</p>
<p>Now, in contrary to Matt Berseth, I am not really concerned with INotifyPropertyChanged, because it is extremely easy to write a meta-helper to auto-implement it for any given object or prototype in JavaScript.</p>
<p>What I <em>am</em> concerned with with is an idea to &#8220;expose methods such as insertRow&#8221; for Client DataSource. I do not have any rows in presentational model or my JavaScript arrays, so I strongly dislike this terminology.</p>
<p>The dream feature for me would be a <a href="http://www.codeplex.com/clinq">Continuous LINQ</a> for JavaScript, where you can dynamically bind to a dynamically filtered collection, bind to products.where(function(p) { return p.Cost &gt; 5; }). We did a basic implementation for this kind of thing, and found it extremely useful for rich web application. You can have a live model behind a complex page, and never explicitly think of updating any part of the page when some collection in the model got changed.</p>
<h4>Animation</h4>
<p>I am not really interested in that &#8212; other frameworks do this kind of thing easier. And if ASP.NET AJAX is going to imitate jQuery syntax, as some people want, why not just use jQuery or mootools?</p>
<h4>Other features</h4>
<p>I think that built-in Drag&amp;Drop may make my life easier, looking forward to it. Also, ASP.NET MVC integration has always been a must, it is nice to see it is coming.</p>
<p>All IDE changes are also very welcome.</p>
<h4>Summary</h4>
<p>In general, I like the proposed changes.</p>
<p>I have a feeling that Microsoft should add more meta helpers as Auto.properties. It is easy to do, but not obvious for the people who are not doing a lot of JavaScript. Also the auto-INotifyPropertyChanged and built-in ObservableCollection would fix databinding cumbersomeness in the same situation.</p>
<p>Also, I am interested in how are the specific technical challenges solved, but it too early to think about that right now.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ashmind.com/2008/07/19/some-thoughts-on-aspnet-ajax-roadmap/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Metaprogramming in JavaScript: Auto properties for ASP.NET AJAX</title>
		<link>http://blog.ashmind.com/2007/10/08/metaprogramming-in-javascript-auto-properties-for-aspnet-ajax/</link>
		<comments>http://blog.ashmind.com/2007/10/08/metaprogramming-in-javascript-auto-properties-for-aspnet-ajax/#comments</comments>
		<pubDate>Mon, 08 Oct 2007 19:20:05 +0000</pubDate>
		<dc:creator>Andrey Shchekin</dc:creator>
				<category><![CDATA[ASP.NET AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Metaprogramming]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://blog.ashmind.com/index.php/2007/10/08/metaprogramming-in-javascript-auto-properties-for-aspnet-ajax/</guid>
		<description><![CDATA[.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: Consolas, "Courier New", Courier, Monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Sometimes, large company is no better than several independent companies.<br /> I always get this thought when looking at ASP.NET AJAX property accessors.</p>
<p>For people not familiar with the matter:<br /> Microsoft ASP.NET AJAX requires developer to use property accessors to encapsulate javascript fields.<br /> This would be a great idea, if only Microsoft IE supported javascript <a href="http://ejohn.org/blog/javascript-getters-and-setters/">getters and setters</a>.<br /> Mozilla supports them, and Opera will in 9.50, but IE does not (they are not standard).<br /> Also, IE does not have any hacky way to achieve the same effect (except in VBScript, which seems to be limited).</p>
<p>So in ASP.NET AJAX each property requires two functions named get<kbd>_propertyName</kbd> and set<kbd>_propertyName</kbd>. </p>
<p>Fortunately, javascript is very powerful in class member manipulation.<br /> So I do not have to write things like this:</p>
<pre class="csharpcode">MyControl.prototype = {
    get_text : <span class="kwrd">function</span>() {
        <span class="kwrd">return</span> <span class="kwrd">this</span>._text;
    },

    set_text : <span class="kwrd">function</span>(value) {
        <span class="kwrd">this</span>._text = value;
    }
}</pre>
<p>And I do not have to wait for auto properties as it is the case for C#.</p>
<p>Instead I just made an helper object named Auto and do things this way:</p>
<pre class="csharpcode">
MyControl.prototype = {…}
Auto.properties(MyControl.prototype, [
    <span class="str">'text'</span>,
    <span class="str">'value'</span>,
    …
]);</pre>
<p>Code for this helper can be very simple.<br />
(in actual project I have additional complexity like Auto support for INotifyPropertyChanged).</p>
<pre class="csharpcode">
<span class="kwrd">var</span> Auto = {
    property : <span class="kwrd">function</span>(prototype, name) {
        <span class="kwrd">var</span> getter = <span class="kwrd">function</span>() { <span class="kwrd">return</span> <span class="kwrd">this</span>[<span class="str">'_'</span> + name]; };
        prototype[<span class="str">'get_'</span> + name] = prototype[<span class="str">'get_'</span> + name] || getter;

        <span class="kwrd">var</span> setter = <span class="kwrd">function</span>(value) { <span class="kwrd">this</span>[<span class="str">'_'</span> + name] = value; };
        prototype[<span class="str">'set_'</span> + name] = prototype[<span class="str">'set_'</span> + name] || setter;
    },

    properties : <span class="kwrd">function</span>(prototype, names) {
        names.forEach(<span class="kwrd">function</span>(name) {
            Auto.property(prototype, name);
        });
    }
}</pre>
<p>This also requires forEach method on Array, but that one is pretty obvious.</p>
<p>I like to show this code when I hear about Javascript being assembly language and whatever-to-javascript compilation.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ashmind.com/2007/10/08/metaprogramming-in-javascript-auto-properties-for-aspnet-ajax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS container class trick</title>
		<link>http://blog.ashmind.com/2007/10/08/css-container-class-trick/</link>
		<comments>http://blog.ashmind.com/2007/10/08/css-container-class-trick/#comments</comments>
		<pubDate>Mon, 08 Oct 2007 17:48:21 +0000</pubDate>
		<dc:creator>Andrey Shchekin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://blog.ashmind.com/index.php/2007/10/08/css-container-class-trick/</guid>
		<description><![CDATA[.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: Consolas, "Courier New", Courier, Monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: Consolas, "Courier New", Courier, Monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Recently I had a debugging session with one of my colleagues and I remebered a simple trick I use often.<br /> Imagine that you have a list of items, and you want to simultaneously change them in response to a user action.</p>
<p>For example, what if you have this list:</p>
<pre class="csharpcode">
<span class="kwrd">&lt;</span><span class="html">ul</span> <span class="attr">class</span><span class="kwrd">="Contacts"</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;</span>Andrey <span class="kwrd">&lt;</span><span class="html">span</span><span class="kwrd">&gt;</span>Shchekin<span class="kwrd">&lt;</span><span class="html">span</span><span class="kwrd">&gt;&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;</span>Nina <span class="kwrd">&lt;</span><span class="html">span</span><span class="kwrd">&gt;</span>Philippova<span class="kwrd">&lt;</span><span class="html">span</span><span class="kwrd">&gt;&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;</span><span class="html">li</span><span class="kwrd">&gt;</span>Gordon <span class="kwrd">&lt;</span><span class="html">span</span><span class="kwrd">&gt;</span>Freeman<span class="kwrd">&lt;</span><span class="html">span</span><span class="kwrd">&gt;&lt;/</span><span class="html">li</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">ul</span><span class="kwrd">&gt;</span></pre>
</p>
<p>And you want to show/hide (expand/collapse) all spans in javascript.</p>
<p>One way to do this would be to go through all spans and change their className.<br />
But that can be quite slow on large list.</p>
<p>The better way is to use something like addClassName (from prototype.js) on <code class="csharpcode"><span class="kwrd">&lt;</span><span class="html">ul</span><span class="kwrd">&gt;</span></code>.</p>
<p>So you change it to <code class="csharpcode"><span class="kwrd">&lt;</span><span class="html">ul</span> <span class="attr">class</span><span class="kwrd">="Contacts AllCollapsed"</span><span class="kwrd">&gt;</span></code> and then apply styles to <code class="csharpcode">.AllCollapsed li span</code>.</p>
<p>This way the browser is responsible for finding all contained elements, which should be faster.<br />
Also, if elements are added dynamically, you do not have to process them.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ashmind.com/2007/10/08/css-container-class-trick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Evaluating Javascript in WatiN</title>
		<link>http://blog.ashmind.com/2007/09/05/evaluating-javascript-in-watin/</link>
		<comments>http://blog.ashmind.com/2007/09/05/evaluating-javascript-in-watin/#comments</comments>
		<pubDate>Wed, 05 Sep 2007 19:52:03 +0000</pubDate>
		<dc:creator>Andrey Shchekin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[COM Interop]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Solutions]]></category>
		<category><![CDATA[WatiN]]></category>

		<guid isPermaLink="false">http://blog.ashmind.com/index.php/2007/09/05/evaluating-javascript-in-watin/</guid>
		<description><![CDATA[The WatiN framework is quite cool, but it lacks two important things.First one is searching by CSS selectors, or, at least, classes.Find.ByCustom(&#8220;className&#8221;, &#8220;X&#8221;) is way too ugly. Or am I missing something? The second (more important) one is a weak access to Javascript.First thing I wanted to do with WatiN was to change something and [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://watin.sourceforge.net/">WatiN</a> framework is quite cool, but it lacks two important things.<br />First one is searching by CSS selectors, or, at least, classes.<br />Find.ByCustom(&#8220;className&#8221;, &#8220;X&#8221;) is way too ugly. Or am I missing something? </p>
<p>The second (more important) one is a weak access to Javascript.<br />First thing I wanted to do with WatiN was to change something and then check some script state.<br />And getting some values from script was not obvious.</p>
<p>I didn&#8217;t want to use <a href="http://www.ayende.com/Blog/archive/2007/04/03/Eval-with-WatiN.aspx">Ayende&#8217;s evil hack</a> (no harm intentended, it gets the work done) — putting javascript state into DOM is not pretty and too string oriented.<br />I thought that browser COM interfaces should definitely have a way to get Javascript <em>objects</em> outside, that is just the way MS/COM people think.<br />Thanks to <a href="http://www.ayende.com/Blog/archive/2007/04/03/Eval-with-WatiN.aspx#Comments_ascx_CommentList_ctl04_NameLink">Jeff Brown&#8217;s comment</a> for explaining last obstacles.</p>
<p>So here goes the code.<br />It is quite basic, but it allows you to get value of any Javascript evaluation.<br />As you can see, I hadn&#8217;t included any error handling, I had no time to look into it. </p>
<pre class="csharpcode">    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> JS {
        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">object</span> Eval(Document document, <span class="kwrd">string</span> code) {
            IExpando window = JS.GetWindow(document);
            PropertyInfo property = JS.GetOrCreateProperty(window, <span class="str">"__lastEvalResult"</span>);

            document.RunScript(<span class="str">"window.__lastEvalResult = "</span> + code + <span class="str">";"</span>);

            <span class="kwrd">return</span> property.GetValue(window, <span class="kwrd">null</span>);
        }

        <span class="kwrd">private</span> <span class="kwrd">static</span> PropertyInfo GetOrCreateProperty(IExpando expando, <span class="kwrd">string</span> name) {
            PropertyInfo property = expando.GetProperty(name, BindingFlags.Instance);
            <span class="kwrd">if</span> (property == <span class="kwrd">null</span>)
                property = expando.AddProperty(name);

            <span class="kwrd">return</span> property;
        }

        <span class="kwrd">private</span> <span class="kwrd">static</span> IExpando GetWindow(Document document) {
            <span class="kwrd">return</span> document.HtmlDocument.parentWindow <span class="kwrd">as</span> IExpando;
        }
    }</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p style="font-size: 90%">Nitpicking:<br />
By the way, <a href="http://www.ayende.com/Blog">Ayende</a>, getting permalinks to comments in your blog is not obvious (I used View Source).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ashmind.com/2007/09/05/evaluating-javascript-in-watin/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Client-side databinding with ASP.Net AJAX Futures</title>
		<link>http://blog.ashmind.com/2007/06/21/client-side-databinding-with-aspnet-ajax-futures/</link>
		<comments>http://blog.ashmind.com/2007/06/21/client-side-databinding-with-aspnet-ajax-futures/#comments</comments>
		<pubDate>Wed, 20 Jun 2007 22:29:52 +0000</pubDate>
		<dc:creator>Andrey Shchekin</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.ashmind.com/index.php/2007/06/21/client-side-databinding-with-aspnet-ajax-futures/</guid>
		<description><![CDATA[Recently I got an optimization problem in ASP.Net.To be short, I had a Repeater with custom (somewhat complex) template on my Page, and I wanted to reload it asynchronously. The first solution was XP and didin&#8217;t consider performance at all: wrap Repeater inside an UpdatePanel.The problem was that the entire Page had to be repopulated [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I got an optimization problem in ASP.Net.<br />To be short, I had a Repeater with custom (somewhat complex) template on my Page, and I wanted to reload it asynchronously.</p>
<p>The first solution was XP and didin&#8217;t consider performance at all: wrap Repeater inside an UpdatePanel.<br />The problem was that the entire Page had to be repopulated on server just to get to the Repeater.</p>
<p>That gave me a choice of two headaches: </p>
<ol>
<li>Put all Page/Controls data into ViewState and bloat bandwidth.
<li>Query all additional data on the reload request and increase load on database to get data that will be thrown away. </li>
</ol>
<p>To be honest, I could solve (2) with server-side cache, but, in my opinion, caching does not make ugly solutions any better, just faster. </p>
<p>So, naturally, my thought was to query the data-only WebService and then populate the Repeater on client.</p>
<p>And it was interesting to find out that Microsoft already has a client-side data binding solution within ASP.Net AJAX Futures.<br />I have found an excellent article on this matter by Xianzhong Zhu, &#8220;Unveil the Data Binding Architecture inside Microsoft ASP.NET Ajax 1.0&#8243; (<a href="http://aspalliance.com/1301_Unveil_the_Data_Binding_Architecture_inside_Microsoft_ASPNET_Ajax_10__Part_1">Part 1</a>, <a href="http://aspalliance.com/1301_Unveil_the_Data_Binding_Architecture_inside_Microsoft_ASPNET_Ajax_10__Part_2">Part 2</a>).</p>
<p>I will now&nbsp;give a quick summary on the overall client-side binding architecture.<br />In essence it is quite similar to the smart DataSource controls of ASP.Net 2.0:<br />There is a DataSource javascript component and a ListView javascript control with html template.<br />ListView passes data from/to DataSource control, and DataSource talks with a JSON Web Service as a backend.<br />Controls and their relations&nbsp;are described in <a href="http://www.nikhilk.net/AtlasXMLScript.aspx">text/xml-script</a> (Futures-only feature).</p>
<p>Everything seems quite straightforward and easy to use, I was quite happy to find it.<br />One thing that bothers me is the performance of text/xml-script (it is parsed on client).<br />But it is a concern not related to the current story.<br />The other question is what to do when I want to databind a complex&nbsp;list (consisting of several embedded server user controls) ?<br />I am going to find it out real soon.</p>
<p>Along the way,&nbsp;I have also&nbsp;noticed&nbsp;Sys.Preview.Data also introduces DataSets/DataTables to javascript.<br />That is quite funny.&nbsp;Personally, I&nbsp;never really considered DataSets acceptable anywhere above Persistence layer.<br />But I already thought about Persistence/DataAccess concept in javascript when I saw <a href="http://gears.google.com/">Gears</a>.<br />And DataSets seem to fit &#8216;nicely&#8217; to some&nbsp;GoogleGearsDataSource (it would be quite an experience to actually see one in real code).</p>
<p>Well, javascript O/R Mapper, anyone ?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ashmind.com/2007/06/21/client-side-databinding-with-aspnet-ajax-futures/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
